instructor-js icon indicating copy to clipboard operation
instructor-js copied to clipboard

[Feature Request] Support Azure Client

Open calclavia opened this issue 1 year ago • 2 comments

Would it be possible to have this library work with Azure's OpenAI client as well?

https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints

calclavia avatar Feb 26 '24 00:02 calclavia

+1

CGSLivv avatar Jul 17 '24 14:07 CGSLivv

Azure OpenAI endpoints work if you use the AzureOpenAI client wrapper from the official OpenAI TypeScript/JavaScript client and pass it to Instructor. I had to create an OpenAI deployment in Azure and a model deployment for the model I wanted to use. When I did that the Azure console showed the API version to use.

Example code:

import { AzureOpenAI } from "openai";
import Instructor from "@instructor-ai/instructor";

const endpointUrl = "https://your-endpoint.openai.azure.com";
const apiKey = "your key";
const apiVersion = "2023-03-15-preview";
const deployment = "gpt-4o";

const client = new AzureOpenAI({ apiVersion, apiKey, endpoint, deployment });
const instructor = Instructor({ client, mode: "TOOLS" });

const user = await instructor.chat.completions.create({
  model: "gpt-4o",
  // ...
});

pdlug avatar Aug 08 '24 20:08 pdlug