Skip to content

Fix v1/chat/completions Gibberish API Responses #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ models/
__pycache__/
*.py[cod]
*$py.class
.DS_STORE


# C extensions
*.so
Expand All @@ -31,6 +33,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
libllama.dylib

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
12 changes: 6 additions & 6 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,13 @@ def _convert_text_completion_chunks_to_chat(
def create_chat_completion(
self,
messages: List[ChatCompletionMessage],
temperature: float = 0.8,
top_p: float = 0.95,
top_k: int = 40,
temperature: float = 0.72,
top_p: float = 0.73,
top_k: int = 0,
stream: bool = False,
stop: List[str] = [],
max_tokens: int = 128,
repeat_penalty: float = 1.1,
max_tokens: int = 256,
repeat_penalty: float = 1/0.85,
) -> Union[ChatCompletion, Iterator[ChatCompletionChunk]]:
"""Generate a chat completion from a list of messages.

Expand All @@ -627,7 +627,7 @@ def create_chat_completion(
f'{message["role"]} {message.get("user", "")}: {message["content"]}'
for message in messages
)
PROMPT = f" \n\n### Instructions:{instructions}\n\n### Inputs:{chat_history}\n\n### Response:\nassistant: "
PROMPT = f"### Instructions:\n{instructions}\n\n{chat_history}\n\n### Response:\nassistant:"
PROMPT_STOP = ["###", "\nuser: ", "\nassistant: ", "\nsystem: "]
completion_or_chunks = self(
prompt=PROMPT,
Expand Down