- תאימות ה-OpenAI API של Qiskit Code Assistant נמצאת בשלב גרסת תצוגה מקדימה וכפופה לשינויים.
- אם יש לך משוב או שתרצה לפנות לצוות המפתחים, השתמש בערוץ Qiskit Slack Workspace או במאגרי GitHub הציבוריים הרלוונטיים.
Qiskit Code Assistant - תאימות ל-OpenAI API
Qiskit Code Assistant מציע תאימות לתת-קבוצה של מפרט OpenAI API, ובפרט לנקודות הקצה של completions API. מטרת תאימות זו היא לאפשר לחבילות צד שלישי להתחבר ל-Qiskit Code Assistant בצורה חלקה על ידי שימוש בספריות ושיטות הקשורות ל-AI ידועות כגון OpenAI, LiteLLM, ואחרות.
נקודות קצה נת מכות של OpenAI API
| Method | Path | Comment |
|---|---|---|
| GET | /v1/models | List all models |
| GET | /v1/model/{model} | Get model detail |
| POST | /v1/completions | Send prompt to model for completion |
נקודת הקצה /v1/completions נכשלת עם שגיאה 403 אם כתב הוויתור של המודל לא אושר. ראה להלן כיצד להציג ולאשר את כתב הוויתור של המודל.
נקודות קצה נוספות (שאינן חלק מסכמת OpenAI, מסופקות לנוחות) כוללות:
| Method | Path | Comment |
|---|---|---|
| GET | /v1/model/{model}/disclaimer | Get model's disclaimer |
| POST | /v1/model/{model}/disclaimer | Accept model's disclaimer |
| POST | /v1/completions/accept | Accept or reject completion |
כדי לאחזר/להציג את כתב הוויתור של המודל, שלח בקשת GET לנקודת הקצה של כתב הוויתור. לדוגמה:
curl -X 'GET' \
'https://qiskit-code-assistant.quantum.ibm.com/v1/model/mistral-small-3.2-24b-qiskit/disclaimer' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <IBM Quantum Classic API key>'
אם אתה מסכים לכתב הוויתור של המודל, כדי לאשר אותו, שלח POST לנקודת הקצה של כתב הוויתור תוך ציון מזהה כתב הוויתור והאם הוא מאושר או נדחה. לדוגמה:
curl -X 'POST' \
'https://qiskit-code-assistant.quantum.ibm.com/v1/model/mistral-small-3.2-24b-qiskit/disclaimer' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <IBM Quantum Classic API key>' \
-H 'Content-Type: application/json' \
-d '{
"disclaimer": "<DISCLAIMER_ID>",
"accepted": true
}'
דוגמאות
שימוש בספריית Python הרשמית של OpenAI
ספריית Python של OpenAI מספקת גישה נוחה ל-OpenAI REST API (כגון זה שמסו פק על ידי Qiskit Code Assistant) מכל יישום Python 3.8+. ראה פרטים נוספים בסעיף ההתקנה של קובץ ה-Readme של ספריית OpenAI Python API.
from openai import OpenAI
# Initialize the client with your API token
client = OpenAI(
api_key="<IBM Quantum Classic API token>",
base_url="https://qiskit-code-assistant.quantum.ibm.com/v1",
)
# Make a request to the completions API
try:
response = client.completions.create(
model="mistral-small-3.2-24b-qiskit",
prompt="#Transpile a random circuit using the Qiskit Transpiler Service",
)
# Print the generated text
print(response.choices[0].text)
except Exception as e:
print(f"An error occurred: {e}")
שימוש ב-LiteLLM
LiteLLM היא ספריית Python נוחה לגישה למספר APIs של LLM בפורמט OpenAI (Bedrock, Huggingface, VertexAI, TogetherAI, Azure, OpenAI, Groq, וכן הלאה). ראה את תיעוד LiteLLM לפרטים נוספים.
from litellm import completion
response = completion(
model=f"text-completion-openai/mistral-small-3.2-24b-qiskit",
base_url="https://qiskit-code-assistant.quantum.ibm.com/v1",
messages=[
{
"role": "user",
"content": "#Transpile a random circuit using the Qiskit Transpiler Service",
}
],
api_key="<IBM Quantum Classic API key>",
)
completion_response = response.json()
print(completion_response)