我目前正在完成微软的语义内核练习,可以在这里
找到但是当我尝试访问图书馆内的服务时出现以下错误。
ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from services import Service
3 # Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)
4 selectedService = Service.OpenAI
ImportError: cannot import name 'Service' from 'services' (c:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\services\__init__.py)
还有其他人遇到过类似的问题吗? pypi 上的
services
库似乎要老得多,而不是 Microsoft 在这里使用的库。
看起来它运行了一些你已经安装的模块
services
但是下面有文件services.py
02-running-prompts-from-file.ipynb
https://github.com/microsoft/semantic-kernel/blob/main/python/notebooks/services.py
您需要将其与代码一起复制到文件夹中。
services.py只有几行,您甚至可以直接将其放入代码中
from enum import Enum
class Service(Enum):
"""
Attributes:
OpenAI (str): Represents the OpenAI service.
AzureOpenAI (str): Represents the Azure OpenAI service.
HuggingFace (str): Represents the HuggingFace service.
"""
OpenAI = "openai"
AzureOpenAI = "azureopenai"
HuggingFace = "huggingface"
或者也许你甚至可以使用
selectedService = "openai"
不使用文件services.py