(model: str = "")
| 99 | |
| 100 | |
| 101 | def run(model: str = ""): # or, e.g., "ollama/mistral:7b-instruct-v0.2-q8_0" |
| 102 | lm_config = lm.OpenAIGPTConfig( |
| 103 | chat_model=model or lm.OpenAIChatModel.GPT4o, # or |
| 104 | ) |
| 105 | tool_name = CompanyInfoTool.default_value("request") |
| 106 | agent_config = lr.ChatAgentConfig( |
| 107 | llm=lm_config, |
| 108 | system_message=f""" |
| 109 | You are a company-info extraction expert. When user gives you a TEXT PASSAGE, |
| 110 | simply extract the company information and |
| 111 | present it using the `{tool_name}` tool/function-call. |
| 112 | """, |
| 113 | ) |
| 114 | agent = lr.ChatAgent(agent_config) |
| 115 | agent.enable_message(CompanyInfoTool) |
| 116 | |
| 117 | # text to present to the LLM |
| 118 | paragraph = """ |
| 119 | Apple Inc. is an American multinational technology company that specializes in |
| 120 | consumer electronics, computer software, and online services. |
| 121 | It has shares outstanding of 16.82 billion, and a price per share of $149.15. |
| 122 | The earnings per share is $5.68. |
| 123 | """ |
| 124 | |
| 125 | # test 1: |
| 126 | # see that the LLM extracts the company information and presents it using the tool |
| 127 | response = agent.llm_response(paragraph) |
| 128 | |
| 129 | print(response.content) |
| 130 | |
| 131 | # test 2: |
| 132 | # wrap the agent in a Task, so that the ToolMessage is handled by the handle method |
| 133 | task = lr.Task(agent, interactive=False) |
| 134 | result = task[FinalResultTool].run(paragraph) |
| 135 | assert result.market_cap > 0 |
| 136 | assert "Apple" in result.info.name |
| 137 | |
| 138 | |
| 139 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected