yangzeyu 1 жил өмнө
parent
commit
879a19559e
3 өөрчлөгдсөн 33 нэмэгдсэн , 0 устгасан
  1. 0 0
      agent/__init__.py
  2. 30 0
      agent/glm.py
  3. 3 0
      requirements.txt

+ 0 - 0
agent/__init__.py


+ 30 - 0
agent/glm.py

@@ -0,0 +1,30 @@
+from config import load_config
+from zhipuai import ZhipuAI
+class Glm:
+    _instance = None
+    def __new__(cls, model_name):
+        if not cls._instance:
+            cls._instance = super(Glm, cls).__new__(cls)
+            cls._instance._initialized = False
+        return cls._instance
+    
+    def __init__(self, model_name):
+        if not self._initialized:
+            self.cfg = load_config()["deepseek"]
+            self.client = ZhipuAI(api_key=self.cfg["api_key"])
+            self._initialized = True
+            
+        self.model_name = model_name
+    
+    def response(self, query):
+        resonse = self.client.chat.completions.create(
+            model=self.model_name,
+            messages=[
+                {"role": "user", "content": query}
+            ],
+        )
+        return resonse.choices[0].message
+    
+if __name__ == '__main__':
+    glm = Glm("glm-4-flash")
+    glm.response("你好")

+ 3 - 0
requirements.txt

@@ -1,5 +1,6 @@
 annotated-types==0.7.0
 anyio==4.8.0
+cachetools==5.5.2
 certifi==2025.1.31
 distro==1.9.0
 dnspython==2.7.0
@@ -14,6 +15,7 @@ openai==1.64.0
 pandas==2.2.3
 pydantic==2.10.6
 pydantic_core==2.27.2
+PyJWT==2.8.0
 pymongo==4.11.1
 python-dateutil==2.9.0.post0
 pytz==2025.1
@@ -23,3 +25,4 @@ sniffio==1.3.1
 tqdm==4.67.1
 typing_extensions==4.12.2
 tzdata==2025.1
+zhipuai==2.1.5.20250106