Skip to content

AI service crashes on startup — openai.ChatCompletion and openai.Embedding no longer exist in SDK v1 #23

@Ananya-CM

Description

@Ananya-CM

The ai-service fails to process any event because the code uses the old
openai SDK syntax which was removed in v1.0.0.

Errors seen in docker logs:

I tried to access openai.ChatCompletion, but this is no longer
supported in openai>=1.0.0

I tried to access openai.Embedding, but this is no longer supported
in openai>=1.0.0

The requirements.txt installs openai==1.3.8 which is the new SDK, but
processor.py still uses the old style:

openai.api_key = config.openai_api_key
openai.ChatCompletion.create(...)
openai.Embedding.create(...)

Fix:
Migrated processor.py to the v1 client interface:

from openai import OpenAI
self.client = OpenAI(api_key=config.openai_api_key)
self.client.chat.completions.create(...)
self.client.embeddings.create(...)

Also fixed the embedding response parsing:
Old: response["data"][0]["embedding"]
New: response.data[0].embedding

After this fix the AI service processes events correctly.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions