isrpa 0.9.7__py3-none-any.whl → 0.9.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
isrpa/llm_chat.py CHANGED
@@ -1,24 +1,54 @@
1
+ from typing import Optional, Dict, Any, List, Union
1
2
  from volcenginesdkarkruntime import Ark
2
- #暂不统计消耗的token,后续要统计再改,无法传递token没法用dify的大模型,先保证这个功能能用起来
3
3
 
4
- def ai_talk(input_str):
5
- """使用方舟SDK调用大模型API"""
4
+
5
+ def ai_query(
6
+ query: str,
7
+ context: Optional[List[Dict[str, str]]] = None,
8
+ model: str = "deepseek-v3-250324",
9
+ **kwargs
10
+ ) -> Union[str, Dict[str, Any]]:
11
+ """
12
+ 向AI发送查询,支持对话上下文和函数调用
13
+
14
+ 参数:
15
+ query: 用户查询文本
16
+ context: 之前的对话上下文(role/content格式)
17
+ model: 使用的AI模型
18
+ **kwargs: 其他API参数(temperature, max_tokens等)
19
+
20
+ 返回:
21
+ 普通回答: 返回字符串
22
+ """
6
23
  try:
7
24
  # 初始化客户端
8
25
  client = Ark(api_key="f0f8b460-c4ea-42a4-a951-5e2e454022ee")
9
26
 
27
+ # 构建消息列表
28
+ messages = []
29
+
30
+ # 添加上下文(如果有)
31
+ if context:
32
+ messages.extend(context)
33
+
34
+ # 添加当前查询
35
+ messages.append({"role": "user", "content": query})
36
+
37
+ # 设置默认参数
38
+ default_params = {
39
+ "model": model,
40
+ "messages": messages,
41
+ "max_tokens": kwargs.get("max_tokens", 2048),
42
+ "temperature": kwargs.get("temperature", 0.5)
43
+ }
44
+
10
45
  # 调用聊天补全API
11
- completion = client.chat.completions.create(
12
- model="deepseek-v3-250324",
13
- messages=[
14
- {"role": "user", "content": input_str}
15
- ],
16
- max_tokens=512, # 最大生成token数
17
- temperature=0.5 # 温度参数
18
- )
19
-
20
- # 返回AI生成的内容
21
- return completion.choices[0].message.content
46
+ completion = client.chat.completions.create(**default_params)
47
+
48
+ # 获取响应内容
49
+ response = completion.choices[0].message.content
50
+
51
+ return response
22
52
 
23
53
  except Exception as e:
24
- return f"ai_talk调用时出错: {str(e)}"
54
+ return f"AI查询时出错: {str(e)}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: isrpa
3
- Version: 0.9.7
3
+ Version: 0.9.8
4
4
  Summary: isrpa package
5
5
  Home-page: https://github.com/yourusername/mypackage
6
6
  Author: ysq
@@ -3,10 +3,10 @@ isrpa/Template.py,sha256=UP1uovLvJzXEPGo_hzLrIYOu3vZP8Cf6m3G2hGzQ6XA,1958
3
3
  isrpa/Template_Exception.py,sha256=an6eQ1NMB8a9R-J0yyMdwHIZcZeDtdV5f7fWKZQsZ3s,819
4
4
  isrpa/__init__.py,sha256=pG-YPVG0gJIJ6s4xcAz9S_CnUxpUcz33wl9eNUSgxGk,20
5
5
  isrpa/credentials.py,sha256=Qgitrm2pKgA1E_iGPg12Qq2Ka52pgTQCBHnT2U62ZHs,3999
6
- isrpa/llm_chat.py,sha256=lrufXl2JnnezXPF3FOMmmQFbqMTLjhCy7ujJTWeu460,863
6
+ isrpa/llm_chat.py,sha256=jTuK9wcm3X36V9lXuGuTCdNup_zi2NeG2GuYHzO7gm4,1541
7
7
  isrpa/message.py,sha256=N0s6hMaC5S-Pi4EhwcSp-ngfBTBQyW6ymU9sI9dUSeE,11329
8
8
  isrpa/utils.py,sha256=uPCb1A1vDB0nTlII2BJz9kS0amk7mvzVA7ilI-UYA8Q,51439
9
- isrpa-0.9.7.dist-info/METADATA,sha256=Y_yaHUXMpR5uicuMfDZ1Mh88aQF_ol7-yiDl-lOdHn0,511
10
- isrpa-0.9.7.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
11
- isrpa-0.9.7.dist-info/top_level.txt,sha256=J5HJbtR2WAeKnW1rrpkiuapwnlswv3RgM-riyZD87o0,6
12
- isrpa-0.9.7.dist-info/RECORD,,
9
+ isrpa-0.9.8.dist-info/METADATA,sha256=LWf7tYP1P5yEyX8DHayHPmQgV8W_Z2fPZzufCbILKAU,511
10
+ isrpa-0.9.8.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
11
+ isrpa-0.9.8.dist-info/top_level.txt,sha256=J5HJbtR2WAeKnW1rrpkiuapwnlswv3RgM-riyZD87o0,6
12
+ isrpa-0.9.8.dist-info/RECORD,,
File without changes