Spaces:
Sleeping
Sleeping
guangliang.yin commited on
Commit ·
bf8722b
1
Parent(s): ef56249
提示词优化-3
Browse files- project/llm/zhipuai_llm.py +12 -2
project/llm/zhipuai_llm.py
CHANGED
|
@@ -31,6 +31,7 @@ from langchain.pydantic_v1 import Field, root_validator
|
|
| 31 |
from langchain.schema.output import GenerationChunk
|
| 32 |
from langchain.utils import get_from_dict_or_env
|
| 33 |
from project.llm.self_llm import Self_LLM
|
|
|
|
| 34 |
|
| 35 |
logger = logging.getLogger(__name__)
|
| 36 |
|
|
@@ -166,10 +167,19 @@ class ZhipuAILLM(Self_LLM):
|
|
| 166 |
return completion
|
| 167 |
params = self._convert_prompt_msg_params(prompt, **kwargs)
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
params = {"messages": [
|
|
|
|
|
|
|
| 172 |
"model": self.model, "stream": False, "top_p": 0.8, "temperature": 0.01, "request_id": None}
|
|
|
|
|
|
|
| 173 |
response_payload = self.client.chat.completions.create(**params)
|
| 174 |
print("response_payload", response_payload)
|
| 175 |
|
|
|
|
| 31 |
from langchain.schema.output import GenerationChunk
|
| 32 |
from langchain.utils import get_from_dict_or_env
|
| 33 |
from project.llm.self_llm import Self_LLM
|
| 34 |
+
import re
|
| 35 |
|
| 36 |
logger = logging.getLogger(__name__)
|
| 37 |
|
|
|
|
| 167 |
return completion
|
| 168 |
params = self._convert_prompt_msg_params(prompt, **kwargs)
|
| 169 |
|
| 170 |
+
all_word = params['prompt']
|
| 171 |
+
|
| 172 |
+
keyword = "问题"
|
| 173 |
+
matches = re.finditer(keyword, all_word)
|
| 174 |
+
indexes = [match.start() for match in matches]
|
| 175 |
+
last_index = indexes[len(indexes) -1]
|
| 176 |
|
| 177 |
+
params = {"messages": [
|
| 178 |
+
{"role": "system", "content": all_word[0:last_index]},
|
| 179 |
+
{"role": "user", "content": all_word[last_index:len(all_word)]}],
|
| 180 |
"model": self.model, "stream": False, "top_p": 0.8, "temperature": 0.01, "request_id": None}
|
| 181 |
+
|
| 182 |
+
print("params:", params)
|
| 183 |
response_payload = self.client.chat.completions.create(**params)
|
| 184 |
print("response_payload", response_payload)
|
| 185 |
|