Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions examples/llm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 📈 Company Info Agent (Powered by LiteLLMModel and DeepSeek)

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.

---

## 🚀 Features

- Query company info by **company name**
- Retrieve **stock code** (e.g. `TSLA`)
- Fetch **basic stock info** and **company details** using tools
- Uses `DeepSeek-chat` LLM via [`LiteLLMModel`](** https://github.com/isekOS/ISEK/tree/main/isek/models/litellm**)
- Fully extensible with other models and tools via ISEK

---

## 🧠 How It Works

The agent uses the following components:

- [`LiteLLMModel`](** https://github.com/isekOS/ISEK/tree/main/isek/models/litellm**): Wrapper for any OpenAI-compatible LLM (e.g., DeepSeek, GPT-4, Claude, etc.)
- [`base_info_tools`]: A collection of tools to retrieve stock codes, stock information, and company details.
- `IsekAgent`: Manages tool usage and reasoning based on instructions.

---

## 🧩 Set Up Environment

Before you try this example, don't forget to modify your .env file:

```bash
DEEPSEEK_API_KEY=your_deepseek_apikay
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
```

## 🔄 Other Example Configs

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:

#### ✅ DeepSeek via Ollama (local deployment)

```python
LiteLLMModel(
provider="ollama",
model_id="deepseek-chat",
base_url="http://localhost:11434",
api_env_key=None # No API key needed for local use
)
```

#### ✅ Claude (Anthropic)

```python
LiteLLMModel(
provider="anthropic",
model_id="claude-3-opus-20240229",
api_env_key="ANTHROPIC_API_KEY"
)
```
27 changes: 27 additions & 0 deletions examples/llm/deepseek_tool_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from isek.agent.isek_agent import IsekAgent
from isek.models.litellm import LiteLLMModel
from isek.models.base import SimpleMessage
from isek.tools.finance_toolkit.get_company_base_info import company_base_info_tools


import dotenv
dotenv.load_dotenv()

agent = IsekAgent(
name="A-Share Company Info Agent",
model=LiteLLMModel(provider = "deepseek", model_id="deepseek/deepseek-chat"),
tools=[company_base_info_tools],
description="An assistant that finds stock info and company info given a company name",
instructions=["Be polite",
"Always first retrieve a numeric stock code (e.g. '600519') and a company 'About' or official website URL base on the company name.",
"Then use the appropriate tool with the stock code to retrieve basic stock information.",
"If a valid 'About' or official website URL is available, use the appropriate tool to fetch additional company details and return it.",
"Always return concise and structured information.",
"Only make tool calls when needed.",
"If a valid stock code or official company URL cannot be found, inform the user explicitly and avoid making unnecessary tool calls."],
success_criteria="User receives the correct stock info and basic company information for the given company name.",
debug_mode=True
)

agent.print_response("hello")
agent.print_response("Give me the base info of Apple company, including its stock info and company info.")
48 changes: 48 additions & 0 deletions isek/tools/finance_toolkit/get_company_base_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from isek.tools.toolkit import Toolkit
import efinance as ef

import requests
from bs4 import BeautifulSoup


def get_stock_info(stock_code: str):
"""get base info of stock base on stock code"""

return ef.stock.get_base_info(stock_code)


def get_company_info(url: str):
"""fetch additional company details base this url"""
headers = {
"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"
}

try:
response = requests.get(url, headers=headers)
response.encoding = "utf-8"
soup = BeautifulSoup(response.text, "html.parser")
return soup.get_text(strip=True)
except Exception:
return ""


# Create toolkit with debug enabled
company_base_info_tools = Toolkit(
name="stock_info_tool",
tools=[get_stock_info, get_company_info],
instructions="Fetch company information based on its stock code and the company's 'About' page or official website URL.",
debug=True,
)


# Optionally, for demonstration, call list_functions and execute_function in debug mode
if __name__ == "__main__":
company_base_info_tools.list_functions()
stock_info = company_base_info_tools.execute_function(
"get_stock_info", stock_code="00020"
)
company_info = company_base_info_tools.execute_function(
"get_company_info", url="https://www.sensetime.com/cn/about-index#1"
)
print("Stock Info:", stock_info)
print("Company Info:", company_info)