microsoft / TypeChat

TypeChat is a library that makes it easy to build natural language interfaces using types.
https://microsoft.github.io/TypeChat/
MIT License
8.06k stars 379 forks source link

Replace usage of OpenAI SDK with direct API calls via httpx. #198

Closed DanielRosenwasser closed 4 months ago

DanielRosenwasser commented 4 months ago

This change aligns the behavior of TypeChat for Python with that of its TypeScript counterpart with respect to Azure OpenAI usage.

While TypeChat for TypeScript simply accepted the fully-formed endpoint URL for chat completions as documented here, the openai package made it so that individual components of that URL had to be threaded through piecemeal (i.e. the deployment name, the model name, the version number, and the API key). What that meant was (at least as far as I could tell), the logic didn't work for Azure OpenAI.

This PR makes it so that TypeChat only cares about the API key and the fully formed URL being placed in your .env file:

AZURE_OPENAI_API_KEY={your-api-key}
AZURE_OPENAI_ENDPOINT=https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}