Skip to content
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

OpenAI v1 Completions API #170

Merged
merged 12 commits into from
Jan 9, 2024
Merged

OpenAI v1 Completions API #170

merged 12 commits into from
Jan 9, 2024

Conversation

tgaddair
Copy link
Contributor

@tgaddair tgaddair commented Jan 9, 2024

Related: #145.

Does not implement chat completions with templates. This will be done in a follow-up.

Python:

from openai import OpenAI

openai_api_key = "EMPTY"
openai_api_base = "http://127.0.0.1:8080/v1"
client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

# synchrounous completions
completion = client.completions.create(
    model=adapter_id,
    prompt=prompt,
)
print("Completion result:", completion[0].choices[0].text)

# streaming completions
completion_stream = client.completions.create(
    model=adapter_id,
    prompt=prompt,
    stream=True,
)

for message in completion_stream:
    print("Completion message:", message)

REST:

curl http://127.0.0.1:8080/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "",
"prompt": "Instruct: Write a detailed analogy between mathematics and a lighthouse.\nOutput:",
"max_tokens": 100
}'

Note that the model param is used in place of the adapter_id in LoRAX. So specifying model="" uses the base model, while model="Yhyu13/phi-2-sft-alpaca_gpt4_en-ep1-lora" would use the given adapter.

@tgaddair tgaddair marked this pull request as ready for review January 9, 2024 22:05
@tgaddair tgaddair mentioned this pull request Jan 9, 2024
36 tasks
@tgaddair tgaddair merged commit 8e479ce into main Jan 9, 2024
1 check passed
@tgaddair tgaddair deleted the completions branch January 9, 2024 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant