forked from TransformerOptimus/SuperAGI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TransformerOptimus#122 from TransformerOptimus/gpt3.5
Added LLM thinking tool
- Loading branch information
Showing
4 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import openai | ||
from typing import Type, Optional | ||
|
||
from pydantic import BaseModel, Field | ||
from superagi.tools.base_tool import BaseTool | ||
from superagi.config.config import get_config | ||
from superagi.llms.base_llm import BaseLlm | ||
from pydantic import BaseModel, Field, PrivateAttr | ||
|
||
|
||
class LlmTaskSchema(BaseModel): | ||
task_description: str = Field( | ||
..., | ||
description="Text describing the task for which the LLM should generate a response.", | ||
) | ||
|
||
class LlmThinkingTool(BaseTool): | ||
llm: Optional[BaseLlm] = None | ||
name = "LlmThinkingTool" | ||
description = ( | ||
"A tool that interacts with any given LLM " | ||
"to generate text given a certain task description." | ||
) | ||
args_schema: Type[LlmTaskSchema] = LlmTaskSchema | ||
|
||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
|
||
def _execute(self, task_description: str): | ||
try: | ||
messages = [{"role": "system", "content": task_description}] | ||
result = self.llm.chat_completion(messages) | ||
return result["content"] | ||
except Exception as e: | ||
print(e) | ||
return f"Error generating text: {e}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters