Skip to content

Commit dc2f61b

Browse files
authored
Merge pull request #74 from xpxxx/main
Add a built-in tool + example tutorial for using LiteLLMModel with DeepSeek provider
2 parents 1c93903 + 0947708 commit dc2f61b

3 files changed

Lines changed: 134 additions & 0 deletions

File tree

examples/llm/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# 📈 Company Info Agent (Powered by LiteLLMModel and DeepSeek)
2+
3+
This example demonstrates how to build a company information agent using the [ISEK](https://github.com/isekOS/ISEK) framework. The agent integrates the `deepseek` large language model via [`LiteLLMModel`](** https://github.com/isekOS/ISEK/tree/main/isek/models/litellm**)and can fetch stock codes and company information for companies.
4+
5+
---
6+
7+
## 🚀 Features
8+
9+
- Query company info by **company name**
10+
- Retrieve **stock code** (e.g. `TSLA`)
11+
- Fetch **basic stock info** and **company details** using tools
12+
- Uses `DeepSeek-chat` LLM via [`LiteLLMModel`](** https://github.com/isekOS/ISEK/tree/main/isek/models/litellm**)
13+
- Fully extensible with other models and tools via ISEK
14+
15+
---
16+
17+
## 🧠 How It Works
18+
19+
The agent uses the following components:
20+
21+
- [`LiteLLMModel`](** https://github.com/isekOS/ISEK/tree/main/isek/models/litellm**): Wrapper for any OpenAI-compatible LLM (e.g., DeepSeek, GPT-4, Claude, etc.)
22+
- [`base_info_tools`]: A collection of tools to retrieve stock codes, stock information, and company details.
23+
- `IsekAgent`: Manages tool usage and reasoning based on instructions.
24+
25+
---
26+
27+
## 🧩 Set Up Environment
28+
29+
Before you try this example, don't forget to modify your .env file:
30+
31+
```bash
32+
DEEPSEEK_API_KEY=your_deepseek_apikay
33+
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
34+
```
35+
36+
## 🔄 Other Example Configs
37+
38+
You can easily switch to other models and providers using [`LiteLLMModel`](** https://github.com/isekOS/ISEK/tree/main/isek/models/litellm**). Here are some common configurations:
39+
40+
#### ✅ DeepSeek via Ollama (local deployment)
41+
42+
```python
43+
LiteLLMModel(
44+
provider="ollama",
45+
model_id="deepseek-chat",
46+
base_url="http://localhost:11434",
47+
api_env_key=None # No API key needed for local use
48+
)
49+
```
50+
51+
#### ✅ Claude (Anthropic)
52+
53+
```python
54+
LiteLLMModel(
55+
provider="anthropic",
56+
model_id="claude-3-opus-20240229",
57+
api_env_key="ANTHROPIC_API_KEY"
58+
)
59+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from isek.agent.isek_agent import IsekAgent
2+
from isek.models.litellm import LiteLLMModel
3+
from isek.models.base import SimpleMessage
4+
from isek.tools.finance_toolkit.get_company_base_info import company_base_info_tools
5+
6+
7+
import dotenv
8+
dotenv.load_dotenv()
9+
10+
agent = IsekAgent(
11+
name="A-Share Company Info Agent",
12+
model=LiteLLMModel(provider = "deepseek", model_id="deepseek/deepseek-chat"),
13+
tools=[company_base_info_tools],
14+
description="An assistant that finds stock info and company info given a company name",
15+
instructions=["Be polite",
16+
"Always first retrieve a numeric stock code (e.g. '600519') and a company 'About' or official website URL base on the company name.",
17+
"Then use the appropriate tool with the stock code to retrieve basic stock information.",
18+
"If a valid 'About' or official website URL is available, use the appropriate tool to fetch additional company details and return it.",
19+
"Always return concise and structured information.",
20+
"Only make tool calls when needed.",
21+
"If a valid stock code or official company URL cannot be found, inform the user explicitly and avoid making unnecessary tool calls."],
22+
success_criteria="User receives the correct stock info and basic company information for the given company name.",
23+
debug_mode=True
24+
)
25+
26+
agent.print_response("hello")
27+
agent.print_response("Give me the base info of Apple company, including its stock info and company info.")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from isek.tools.toolkit import Toolkit
2+
import efinance as ef
3+
4+
import requests
5+
from bs4 import BeautifulSoup
6+
7+
8+
def get_stock_info(stock_code: str):
9+
"""get base info of stock base on stock code"""
10+
11+
return ef.stock.get_base_info(stock_code)
12+
13+
14+
def get_company_info(url: str):
15+
"""fetch additional company details base this url"""
16+
headers = {
17+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
18+
}
19+
20+
try:
21+
response = requests.get(url, headers=headers)
22+
response.encoding = "utf-8"
23+
soup = BeautifulSoup(response.text, "html.parser")
24+
return soup.get_text(strip=True)
25+
except Exception:
26+
return ""
27+
28+
29+
# Create toolkit with debug enabled
30+
company_base_info_tools = Toolkit(
31+
name="stock_info_tool",
32+
tools=[get_stock_info, get_company_info],
33+
instructions="Fetch company information based on its stock code and the company's 'About' page or official website URL.",
34+
debug=True,
35+
)
36+
37+
38+
# Optionally, for demonstration, call list_functions and execute_function in debug mode
39+
if __name__ == "__main__":
40+
company_base_info_tools.list_functions()
41+
stock_info = company_base_info_tools.execute_function(
42+
"get_stock_info", stock_code="00020"
43+
)
44+
company_info = company_base_info_tools.execute_function(
45+
"get_company_info", url="https://www.sensetime.com/cn/about-index#1"
46+
)
47+
print("Stock Info:", stock_info)
48+
print("Company Info:", company_info)

0 commit comments

Comments
 (0)