Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
patcher9 committed Mar 14, 2024
1 parent 7acc946 commit 08930f7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
File renamed without changes.
62 changes: 62 additions & 0 deletions tests/test_mistral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Mistral Test Suite
This module contains a suite of tests for Mistral functionality
using the Mistral Python library. It includes tests for various
Mistral API endpoints such as text summarization, text generation
with a prompt,text embeddings creation, and chat-based
language understanding.
The tests are designed to cover different aspects of Mistral's
capabilities and serve as a validation mechanism for the integration
with the Doku monitoring system.
Global Mistral client and initialization are set up for the
Mistral client and Doku monitoring.
Environment Variables:
- Mistral_API_TOKEN: Mistral API api_key for authentication.
- DOKU_URL: Doku URL for monitoring data submission.
- DOKU_TOKEN: Doku authentication api_key.
Note: Ensure the environment variables are properly set before running the tests.
"""

import os
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
import dokumetry

# Global Mistral client
client = MistralClient(
api_key=os.getenv("MISTRAL_API_TOKEN")
)

# Global Mistral initialization
# pylint: disable=line-too-long
dokumetry.init(llm=client, doku_url=os.getenv("DOKU_URL"), api_key=os.getenv("DOKU_TOKEN"), environment="dokumetry-testing", application_name="dokumetry-python-test", skip_resp=False)

def test_chat():
"""
Test the 'chat' function of the Mistral client.
"""
messages = [
ChatMessage(role="user", content="What is the best French cheese?")
]

# No streaming
message = client.chat(
model="mistral-large-latest",
messages=messages,
)
assert message.object == 'chat.completion'

def test_embeddings():
"""
Test the 'embeddings' function of the Mistral client.
"""
response = client.embeddings(
model="mistral-embed",
input=["Embed this sentence.", "As well as this one."],
)
assert response.object == 'list'

0 comments on commit 08930f7

Please sign in to comment.