test_scaleway.py 920 B

12345678910111213141516171819202122232425262728293031323334
  1. from openai import OpenAI
  2. SCW_API_KEY = "ad99d6a9-b71e-457d-855a-4d4b5f9abdda"
  3. SCW_MODEL = "mistral-small-3.2-24b-instruct-2506"
  4. BASE_URL = "https://api.scaleway.ai/d7d5949a-c2bb-484a-b973-e05a83510efd/v1"
  5. client = OpenAI(
  6. base_url=BASE_URL,
  7. api_key=SCW_API_KEY
  8. )
  9. print(f"Appel vers : {BASE_URL}")
  10. print(f"Modèle : {SCW_MODEL}\n")
  11. print("Réponse du modèle : ", end="", flush=True)
  12. response = client.chat.completions.create(
  13. model=SCW_MODEL,
  14. messages=[
  15. {"role": "system", "content": "You are a helpful assistant"},
  16. {"role": "user", "content": "Dis bonjour en une phrase."}
  17. ],
  18. max_tokens=512,
  19. temperature=0.15,
  20. top_p=1,
  21. presence_penalty=0,
  22. stream=True,
  23. response_format={"type": "text"}
  24. )
  25. for chunk in response:
  26. if chunk.choices and chunk.choices[0].delta.content:
  27. print(chunk.choices[0].delta.content, end="", flush=True)
  28. print()