jinysun commited on
Commit
98bae50
·
verified ·
1 Parent(s): c69c78d

Update tool/coder.py

Browse files
Files changed (1) hide show
  1. tool/coder.py +43 -43
tool/coder.py CHANGED
@@ -1,43 +1,43 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- Created on Sat Oct 26 15:35:19 2024
4
-
5
- @author: BM109X32G-10GPU-02
6
- """
7
-
8
- from langchain_community.embeddings import OllamaEmbeddings
9
- from langchain.tools import BaseTool
10
- from langchain_openai import ChatOpenAI
11
- from langchain_core.messages import HumanMessage, SystemMessage
12
- from langchain.base_language import BaseLanguageModel
13
-
14
-
15
- class codewriter(BaseTool):
16
- name:str = "codewriter"
17
- description:str = (
18
- "Useful to answer questions that require writing codes "
19
- "return the usage and instruction of codes"
20
- )
21
-
22
- llm: BaseLanguageModel = None
23
- def __init__(self):
24
- super().__init__()
25
- self.llm = ChatOpenAI(model="gpt-4o-2024-11-20",api_key='sk-itPrztYm9F6XZZpsBMJB9O7Vq0pYUABVVBSoThuBxEGTnDik',
26
- base_url="https://www.dmxapi.com/v1")
27
- # api keys
28
-
29
- def _run(self, query) -> str:
30
- messages = [
31
- SystemMessage(content="You are an expert at writing code, write the corresponding code based on the inputs"),
32
- HumanMessage(content=query),
33
- ]
34
-
35
- response = self.llm.invoke(messages)
36
- return response
37
-
38
- async def _arun(self, query) -> str:
39
- """Use the tool asynchronously."""
40
- raise NotImplementedError("this tool does not support async")
41
-
42
-
43
-
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Sat Oct 26 15:35:19 2024
4
+
5
+ @author: BM109X32G-10GPU-02
6
+ """
7
+
8
+ from langchain_community.embeddings import OllamaEmbeddings
9
+ from langchain.tools import BaseTool
10
+ from langchain_openai import ChatOpenAI
11
+ from langchain_core.messages import HumanMessage, SystemMessage
12
+ from langchain.base_language import BaseLanguageModel
13
+
14
+
15
+ class codewriter(BaseTool):
16
+ name:str = "codewriter"
17
+ description:str = (
18
+ "Useful to answer questions that require writing codes "
19
+ "return the usage and instruction of codes"
20
+ )
21
+
22
+ llm: BaseLanguageModel = None
23
+ def __init__(self):
24
+ super().__init__()
25
+ self.llm = ChatOpenAI(model="gpt-4o-2024-11-20",api_key=os.getenv("OPENAI_API_KEY"),
26
+ base_url=os.getenv("OPENAI_API_BASE"))
27
+ # api keys
28
+
29
+ def _run(self, query) -> str:
30
+ messages = [
31
+ SystemMessage(content="You are an expert at writing code, write the corresponding code based on the inputs"),
32
+ HumanMessage(content=query),
33
+ ]
34
+
35
+ response = self.llm.invoke(messages)
36
+ return response
37
+
38
+ async def _arun(self, query) -> str:
39
+ """Use the tool asynchronously."""
40
+ raise NotImplementedError("this tool does not support async")
41
+
42
+
43
+