fix: 🐛 numerous small fixes

This commit is contained in:
Nate Sesti 2023-09-13 11:07:21 -07:00
parent 8cce7eb46b
commit 0940d756de
5 changed files with 27 additions and 20 deletions

View file

@ -42,6 +42,10 @@ class GGML(LLM):
None,
description="Whether SSL certificates should be verified when making the HTTP request",
)
proxy: Optional[str] = Field(
None,
description="Proxy URL to use when making the HTTP request",
)
ca_bundle_path: str = Field(
None,
description="Path to a custom CA bundle to use when making the HTTP request",
@ -96,6 +100,7 @@ class GGML(LLM):
**args,
},
headers=self.get_headers(),
proxy=self.proxy,
) as resp:
async for line in resp.content.iter_any():
if line:
@ -129,6 +134,7 @@ class GGML(LLM):
f"{self.server_url}/v1/chat/completions",
json={"messages": messages, "stream": True, **args},
headers=self.get_headers(),
proxy=self.proxy,
) as resp:
async for line, end in resp.content.iter_chunks():
json_chunk = line.decode("utf-8")
@ -165,6 +171,7 @@ class GGML(LLM):
**args,
},
headers=self.get_headers(),
proxy=self.proxy,
) as resp:
text = await resp.text()
try:

View file

@ -31,11 +31,10 @@ class HuggingFaceTGI(LLM):
def collect_args(self, options: CompletionOptions) -> Any:
args = super().collect_args(options)
args = {
**args,
"max_new_tokens": args.get("max_tokens", 1024),
}
args.pop("max_tokens", None)
args = {**args, "max_new_tokens": args.get("max_tokens", 1024), "best_of": 1}
args.pop("max_tokens")
args.pop("model")
args.pop("functions")
return args
async def _stream_complete(self, prompt, options):
@ -46,13 +45,17 @@ class HuggingFaceTGI(LLM):
timeout=aiohttp.ClientTimeout(total=self.timeout),
) as client_session:
async with client_session.post(
f"{self.server_url}",
json={"inputs": prompt, "stream": True, **args},
f"{self.server_url}/generate_stream",
json={"inputs": prompt, "parameters": args},
) as resp:
async for line in resp.content.iter_any():
if line:
chunk = line.decode("utf-8")
json_chunk = json.loads(chunk)
try:
json_chunk = json.loads(chunk)
except Exception as e:
print(f"Error parsing JSON: {e}")
continue
text = json_chunk["details"]["best_of_sequences"][0][
"generated_text"
]

View file

@ -45,14 +45,8 @@ po_box = re.compile(r"P\.? ?O\.? Box \d+", re.IGNORECASE)
ssn = re.compile(
"(?!000|666|333)0*(?:[0-6][0-9][0-9]|[0-7][0-6][0-9]|[0-7][0-7][0-2])[- ](?!00)[0-9]{2}[- ](?!0000)[0-9]{4}"
)
win_absolute_filepath = re.compile(
r"^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.$]+)\\(?:[\w]+\\)*\w([\w.])+", re.IGNORECASE
)
unix_absolute_filepath = re.compile(r"^\/(?:[\/\w]+\/)*\w([\w.])+", re.IGNORECASE)
regexes = {
"win_absolute_filepath": win_absolute_filepath,
"unix_absolute_filepath": unix_absolute_filepath,
"dates": date,
"times": time,
"phones": phone,
@ -71,8 +65,6 @@ regexes = {
}
placeholders = {
"win_absolute_filepath": "<FILEPATH>",
"unix_absolute_filepath": "<FILEPATH>",
"dates": "<DATE>",
"times": "<TIME>",
"phones": "<PHONE>",

View file

@ -18,8 +18,11 @@ DEFAULT_ARGS = {
"temperature": 0.5,
}
already_saw_import_err = False
def encoding_for_model(model_name: str):
global already_saw_import_err
try:
import tiktoken
from tiktoken_ext import openai_public # noqa: F401
@ -29,7 +32,9 @@ def encoding_for_model(model_name: str):
except:
return tiktoken.encoding_for_model("gpt-3.5-turbo")
except Exception as e:
print("Error importing tiktoken", e)
if not already_saw_import_err:
print("Error importing tiktoken", e)
already_saw_import_err = True
return None

View file

@ -22,7 +22,7 @@ const sidebars = {
type: "category",
label: "🎨 Customization",
collapsible: true,
collapsed: false,
collapsed: true,
items: [
"customization/overview",
"customization/models",
@ -35,7 +35,7 @@ const sidebars = {
type: "category",
label: "🚶 Walkthroughs",
collapsible: true,
collapsed: false,
collapsed: true,
items: ["walkthroughs/codellama"],
},
"development-data",
@ -45,7 +45,7 @@ const sidebars = {
type: "category",
label: "📖 Reference",
collapsible: true,
collapsed: false,
collapsed: true,
items: [
{
type: "autogenerated",