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

Update PyO3 to take dict #257

Merged
merged 2 commits into from
Apr 30, 2024
Merged

Update PyO3 to take dict #257

merged 2 commits into from
Apr 30, 2024

Conversation

EricLBuehler
Copy link
Owner

This increases compatibility with OpenAI and llama-cpp-python. I would appreciate any thoughts on this change.

Breaking

This breaks any code which uses the chat completion API as it removes the Message and Role classes.

Sample change

from mistralrs import Runner, Which, ChatCompletionRequest, Message, Role

runner = Runner(
    which=Which.GGUF(
        tok_model_id="mistralai/Mistral-7B-Instruct-v0.1",
        quantized_model_id="TheBloke/Mistral-7B-Instruct-v0.1-GGUF",
        quantized_filename="mistral-7b-instruct-v0.1.Q4_K_M.gguf",
        tokenizer_json=None,
        repeat_last_n=64,
    )
)

res = runner.send_chat_completion_request(
    ChatCompletionRequest(
        model="mistral",
-       messages=[Message(Role.User, "Tell me a story about the Rust type system.")],
+       messages=[{"role":"user", "content":"Tell me a story about the Rust type system."}],
        max_tokens=256,
        presence_penalty=1.0,
        top_p=0.1,
        temperature=0.1,
    )
)
print(res.choices[0].message.content)
print(res.usage)

Copy link

Code Metrics Report
  ───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Rust                        70     23717     1560       511    21646       1313
───────────────────────────────────────────────────────────────────────────────
Total                       70     23717     1560       511    21646       1313
───────────────────────────────────────────────────────────────────────────────
Estimated Cost to Develop 81,933
Estimated Schedule Effort 11.891481 months
Estimated People Required 5.094738
───────────────────────────────────────────────────────────────────────────────
Processed 784984 bytes, 0.785 megabytes (SI)
───────────────────────────────────────────────────────────────────────────────
  

Copy link
Owner Author

@EricLBuehler EricLBuehler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@EricLBuehler EricLBuehler merged commit dbbfca4 into master Apr 30, 2024
11 checks passed
@EricLBuehler EricLBuehler deleted the pyo3_api_dict branch April 30, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant