自定义大型语言模型 (LLM)
我们支持并欢迎在 UFO 中集成自定义 LLM 模型。如果您有希望与 UFO 一起使用的自定义 LLM 模型,可以按照以下步骤在 UFO 中配置该模型。
第一步
创建自定义 LLM 模型并在您的本地环境中进行部署。
第二步
在 ufo/llm
目录下创建一个 Python 脚本,并通过继承 ufo/llm/base.py
文件中的 BaseService
类来实现您自己的 LLM 模型类。我们在 ufo/llm/placeholder.py
文件中保留了一个 PlaceHolderService
类作为示例。您必须在您的 LLM 模型类中实现 chat_completion
方法,以接受消息列表并返回每条消息的补全列表。
def chat_completion(
self,
messages,
n,
temperature: Optional[float] = None,
max_tokens: Optional[int] = None,
top_p: Optional[float] = None,
**kwargs: Any,
):
"""
Generates completions for a given list of messages.
Args:
messages (List[str]): The list of messages to generate completions for.
n (int): The number of completions to generate for each message.
temperature (float, optional): Controls the randomness of the generated completions. Higher values (e.g., 0.8) make the completions more random, while lower values (e.g., 0.2) make the completions more focused and deterministic. If not provided, the default value from the model configuration will be used.
max_tokens (int, optional): The maximum number of tokens in the generated completions. If not provided, the default value from the model configuration will be used.
top_p (float, optional): Controls the diversity of the generated completions. Higher values (e.g., 0.8) make the completions more diverse, while lower values (e.g., 0.2) make the completions more focused. If not provided, the default value from the model configuration will be used.
**kwargs: Additional keyword arguments to be passed to the underlying completion method.
Returns:
List[str], None:A list of generated completions for each message and the cost set to be None.
Raises:
Exception: If an error occurs while making the API request.
"""
pass
第三步
在实现 LLM 模型类之后,您可以在 config.yaml
文件(将 config_template.yaml
文件重命名为 config.yaml
)中配置 HOST_AGENT
和 APP_AGENT
以使用自定义 LLM 模型。以下是自定义 LLM 模型的配置示例:
VISUAL_MODE: True, # Whether to use visual mode to understand screenshots and take actions
API_TYPE: "custom_model" , # The API type, "openai" for the OpenAI API, "aoai" for the AOAI API, 'azure_ad' for the ad authority of the AOAI API.
API_BASE: "YOUR_ENDPOINT", # The custom LLM API address.
API_MODEL: "YOUR_MODEL", # The custom LLM model name.
步骤 4
在为 HOST_AGENT
和 APP_AGENT
配置自定义 LLM 模型后,您就可以开始使用 UFO 与自定义 LLM 模型进行交互,以完成 Windows 操作系统上的各种任务。有关如何开始使用 UFO 的更多详细信息,请参阅快速入门指南。