Skip to content

Commit

Permalink
Fix the issue of error occurring when answering search queries with e…
Browse files Browse the repository at this point in the history
…xcessive length in gpt-3.5-turbo. update g4f version to 0.1.7.9
  • Loading branch information
yym68686 committed Oct 31, 2023
1 parent 968e5fd commit f4bc19c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions chatgpt2api/chatgpt2api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(
if "gpt-3.5-turbo-16k" in engine
else 98500
if "claude-2-web" in engine
else 3500
else 3400
)
self.temperature: float = temperature
self.top_p: float = top_p
Expand Down Expand Up @@ -520,20 +520,22 @@ def search_summary(
encode_text = encoding.encode(useful_source_text)
encode_fact_text = encoding.encode(fact_text)

if len(encode_text) > self.max_tokens:
encode_text = encode_text[:self.max_tokens-len(encode_fact_text)]
if len(encode_text) > self.truncate_limit:
encode_text = encode_text[:self.truncate_limit-len(encode_fact_text)]
useful_source_text = encoding.decode(encode_text)
encode_text = encoding.encode(useful_source_text)
tokens_len = len(encode_text)
search_tokens_len = len(encode_text)
print("web search", useful_source_text, end="\n\n")

print(url_set_list)
print("pdf", url_pdf_set_list)
if config.USE_GOOGLE:
print("google search keyword", keyword)
print(f"搜索用时:{run_time}秒")
print("tokens_len", tokens_len)
print("search tokens len", search_tokens_len)
useful_source_text = useful_source_text + "\n\n" + fact_text
text_len = len(encoding.encode(useful_source_text))
print("text len", text_len)
summary_prompt = PromptTemplate(
input_variables=["web_summary", "question"],
template=(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ unstructured[pdf]
duckduckgo-search==3.8.5
langchain==0.0.271
oauth2client==3.0.0
g4f==0.1.7.7
g4f==0.1.7.9

0 comments on commit f4bc19c

Please sign in to comment.