ai-agents-for-beginners icon indicating copy to clipboard operation
ai-agents-for-beginners copied to clipboard

First code does not run

Open etellezgh opened this issue 10 months ago • 2 comments

Describe the bug running the 01-semantic-kernel.ipynb i found that the last code cannot be executed

To Reproduce Steps to reproduce the behavior: 1.running the complete notebook

Expected behavior Should work but no

Screenshots there the error raised


InternalServerError Traceback (most recent call last) File c:\Python311\Lib\site-packages\semantic_kernel\connectors\ai\open_ai\services\open_ai_handler.py:87, in OpenAIHandler._send_completion_request(self, settings) 86 settings_dict.pop("parallel_tool_calls", None) ---> 87 response = await self.client.chat.completions.create(**settings_dict) 88 else:

File ~\AppData\Roaming\Python\Python311\site-packages\openai\resources\chat\completions\completions.py:2028, in AsyncCompletions.create(self, messages, model, audio, frequency_penalty, function_call, functions, logit_bias, logprobs, max_completion_tokens, max_tokens, metadata, modalities, n, parallel_tool_calls, prediction, presence_penalty, reasoning_effort, response_format, seed, service_tier, stop, store, stream, stream_options, temperature, tool_choice, tools, top_logprobs, top_p, user, web_search_options, extra_headers, extra_query, extra_body, timeout) 2027 validate_response_format(response_format) -> 2028 return await self._post( 2029 "/chat/completions", 2030 body=await async_maybe_transform( 2031 { 2032 "messages": messages, 2033 "model": model, 2034 "audio": audio, 2035 "frequency_penalty": frequency_penalty, 2036 "function_call": function_call, 2037 "functions": functions, 2038 "logit_bias": logit_bias, 2039 "logprobs": logprobs, 2040 "max_completion_tokens": max_completion_tokens, 2041 "max_tokens": max_tokens, 2042 "metadata": metadata, 2043 "modalities": modalities, ... 105 f"{type(self)} service failed to complete the prompt", 106 ex, 107 ) from ex

ServiceResponseException: ("<class 'semantic_kernel.connectors.ai.open_ai.services.open_ai_chat_completion.OpenAIChatCompletion'> service failed to complete the prompt", InternalServerError("Error code: 500 - {'error': {'code': 'unknown', 'message': 'Unhandled exception: Specified method is not supported.', 'details': 'Unhandled exception: Specified method is not supported.'}}"))

Desktop (please complete the following information):

  • OS: Windows 11
  • inside VS Code

etellezgh avatar Apr 24 '25 17:04 etellezgh

👋 Thanks for contributing @etellezgh! We will review the issue and get back to you soon.

github-actions[bot] avatar Apr 24 '25 17:04 github-actions[bot]

Issue with Semantic Kernel Notebook Imports

Hey team,

I’m trying to run the 01-semantic-kernel.ipynb notebook in a virtual environment with the required package versions (semantic_kernel>=1.27.2, pydantic>=2.10.0,<3.0.0, plus openai, python-dotenv, etc). However, I’m stuck on the cell where we import everything due to two errors:

  1. First Error: Got an ImportError: cannot import name 'Url' from 'pydantic.networks'. I fixed this by patching the import to use HttpUrl for pydantic v2 compatibility, as Url was removed in pydantic>=2.0.

  2. Second Error: After resolving the first issue, I now get ModuleNotFoundError: No module named 'semantic_kernel.agents' when importing ChatCompletionAgent and ChatHistoryAgentThread. It seems the agents module might not exist in semantic_kernel==1.27.2 or was moved (tried semantic_kernel.experimental.agents but no luck).

I’ve set up a fresh virtual environment, installed the exact versions, and restarted the Jupyter kernel, but I can’t get past this cell. Could you confirm if the notebook is compatible with semantic_kernel>=1.27.2? If the agents module was restructured, what’s the updated import path or recommended version? Any help or updated code would be great!

Thanks, Tammy Python 3.12.10 Mac OS Sequoia 15.4.1

tdiprima avatar May 05 '25 14:05 tdiprima

Thanks for reporting, working on a fix. Will submit a PR when complete.

koreyspace avatar May 08 '25 12:05 koreyspace

Hey @tdiprima and @etellezgh - I wasnt able to reproduce this but I was I have update the requriements.txt file to support the lastest version of SK and remove Pydantic in case there is a conflict here. Can you try reinstalling?

pip uninstall -r requirements.txt -y
pip install -r requirements.txt

koreyspace avatar May 09 '25 15:05 koreyspace

Hi @koreyspace - it worked for me. Thanks for looking into this.

tdiprima avatar May 09 '25 15:05 tdiprima

Hey @etellezgh — just a heads up, I noticed a lot of 'Python311' in your message. The setup guide says to use python3.12 instead. Switching to that is what got things working for me!

tdiprima avatar May 09 '25 15:05 tdiprima

Closing this for now - if you still have issues @etellezgh please reopen

koreyspace avatar May 16 '25 14:05 koreyspace