Skip to content

Commit 0dd7de9

Browse files
add chain of thought example
1 parent 5d905ca commit 0dd7de9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
from core.chain_of_thought_agent import ChainOfThoughtAgent
3+
4+
async def run_chain_of_thought_example():
5+
question = 'What is the square root of 144?'
6+
agent = ChainOfThoughtAgent(question=question)
7+
result = await agent.chain_of_thought()
8+
9+
print("Question:", question)
10+
print("Chain of Thought Reasoning:", result)
11+
12+
if __name__ == "__main__":
13+
asyncio.run(run_chain_of_thought_example())

src/core/chain_of_thought_agent.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import asyncio
2+
from typing import List
3+
from .openai_api import OpenAIClient
4+
5+
class ChainOfThoughtAgent:
6+
def __init__(self, question: str, max_tokens: int = 1000, temperature: float = 0.0):
7+
self.question = question
8+
self.max_tokens = max_tokens
9+
self.temperature = temperature
10+
self.openai_client = OpenAIClient()
11+
12+
async def chain_of_thought(self) -> str:
13+
system_prompt = "You are an assistant tasked with solving problems using the 'chain of thought' reasoning process."
14+
user_prompt = f"Solve the following problem step-by-step: {self.question}"
15+
16+
response = await self.openai_client.complete_chat([
17+
{"role": "system", "content": system_prompt},
18+
{"role": "user", "content": user_prompt}
19+
], max_tokens=self.max_tokens)
20+
21+
return response.strip()

0 commit comments

Comments
 (0)