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

Add support for AzureOpenAI #1161

Closed
samarth6341 opened this issue Nov 9, 2024 · 5 comments
Closed

Add support for AzureOpenAI #1161

samarth6341 opened this issue Nov 9, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@samarth6341
Copy link

No description provided.

@github-actions github-actions bot added the enhancement New feature or request label Nov 9, 2024
@ivanleomk
Copy link
Collaborator

Question - I'm not super familiar with the Azure OpenAI client.

Can you not use the normal OpenAI client and just change the api endpoint and auth params?

How does the azure OpenAI client differ

@qkxie
Copy link

qkxie commented Nov 12, 2024

@ivanleomk This is very simple.

from openai import AzureOpenAI
llm = AzureOpenAI(your params)
client = instructor.from_openai(llm)

In fact, any LLM which is compatible with openAI SDK can use this method.

@Flopsky
Copy link

Flopsky commented Nov 13, 2024

Here is more precise exemple

import instructor
from openai import AzureOpenAI
from pydantic import BaseModel

# Define your data model
class UserInfo(BaseModel):
    name: str
    age: int

# Initialize the Azure OpenAI client with your credentials
client = AzureOpenAI(
    api_key="your-azure-api-key",  
    azure_endpoint="https://your-resource-name.openai.azure.com",  # Your Azure endpoint
    #add your oder params
) 

# Patch the client with instructor
client = instructor.from_openai(client)

# Use the patched client to extract structured data
user_info = client.chat.completions.create(
    model="your-deployed-model-name",  # The name you gave to your deployed model
    response_model=UserInfo,
    messages=[
        {"role": "user", "content": "John Doe is 30 years old."}
    ]
)

print(user_info.name)  # Output: John Doe
print(user_info.age)   # Output: 30

@samarth6341
Copy link
Author

Thank you so much.

@ivanleomk
Copy link
Collaborator

Closing this issue since it's possible to do so with the default OpenAI integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants