8000 Update Azure endpoint integration and refactor for GitHub models in bia-bob repository. by github-actions[bot] · Pull Request #238 · haesleinhuepf/bia-bob · GitHub
[go: up one dir, main page]

Skip to content

Update Azure endpoint integration and refactor for GitHub models in bia-bob repository. - #238

Open
github-actions[bot] wants to merge 7 commits into
mainfrom
git-bob-mod-0wqvgw9l6b
Open

github-actions[bot] wants to merge 7 commits into
mainfrom
git-bob-mod-0wqvgw9l6b

Conversation

@github-actions
@github-actions github-actions Bot commented Apr 3, 2025
Copy link
Copy Markdown
Contributor

This message was generated by git-bob (version: 0.21.0, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

This pull request addresses issue #237 (and also closes #236) by updating the structure of the Azure endpoint implementation in the bia-bob repository. The previous Azure integration was moved from src/bia_bob/endpoints/_azure.py into a new file src/bia_bob/endpoints/_github_models.py, allowing for a dedicated function named prompt_github_models. The prompt_azure function was then implemented in src/bia_bob/endpoints/_azure.py to tailor it for Azure's needs using AzureOpenAI. Additionally, the generate_response function in src/bia_bob/_utilities.py was updated to include a new if-block for handling github_models endpoints, ensuring better configuration and adaptability for different models.

closes #237

@haesleinhuepf
Copy link
Copy Markdown
Owner

The parameters of the new prompt_azure function and the code in the new prompt_azure function are incomplete. Extend it with the functionality from src/bia_bob/endpoints/_openai.py.

git-bob implement this

…parameters with those from `src/bia_bob/endpoints/_openai.py`.
@github-actions
Copy link
Copy Markdown
Contributor Author

This message was generated by git-bob (version: 0.21.0, model: gpt-4o-2024-08-06, log), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

In response to the issue discussions for GitHub issues #236 and #237, the Azure endpoint integration was refined by moving the existing functionality from _azure.py to a newly created _github_models.py for GitHub API tasks. This restructuring involved the creation of a prompt_github_models function. A prompt_azure function was also implemented in _azure.py to better accommodate Azure's requirements through the AzureOpenAI client. Additionally, the generate_response function in _utilities.py was enhanced to address the new endpoints. Based on a suggestion from @haesleinhuepf, the prompt_azure function's parameters and code were aligned with those found in _openai.py to ensure they were complete.

During solving this task, the following errors occurred:

  • Error during {'action': 'modify', 'filename': 'src/bia_bob//_utilities.py'}: path contains a malformed path component: 422 {"message": "path contains a malformed path component", "errors": [{"resource": "Commit", "field": "path", "code": "invalid"}], "documentation_url": "https://docs.github.com/rest/repos/contents#create-or-update-file-contents", "status": "422"}
        Traceback (most recent call last):
        File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/git_bob/_ai_github_utilities.py", line 645, in solve_github_issue
          created_files = create_or_modify_file(repository, issue, filename, branch_name, discussion,
                                                                prompt_function)
        File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/git_bob/_ai_github_utilities.py", line 513, in create_or_modify_file
          Config.git_utilities.write_file_in_branch(repository, branch_name, filename, new_content, redact_text(commit_message))
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/git_bob/_github_utilities.py", line 371, in write_file_in_branch
          repo.create_file(file_path, commit_message, new_content, branch=branch_name)
          ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/github/Repository.py", line 2707, in create_file
          headers, data = self._requester.requestJsonAndCheck(
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
              "PUT",
              ^^^^^^
              f"{self.url}/contents/{urllib.parse.quote(path)}",
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              input=put_parameters,
              ^^^^^^^^^^^^^^^^^^^^^
          )
          ^
        File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/github/Requester.py", line 624, in requestJsonAndCheck
          return self.__check(
                 ~~~~~~~~~~~~^
              *self.requestJson(
              ^^^^^^^^^^^^^^^^^^
          ...<7 lines>...
              )
              ^
          )
          ^
        File "/opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/github/Requester.py", line 792, in __check
          raise self.createException(status, responseHeaders, data)
      github.GithubException.GithubException: path contains a malformed path component: 422 {"message": "path contains a malformed path component", "errors": [{"resource": "Commit", "field": "path", "code": "invalid"}], "documentation_url": "https://docs.github.com/rest/repos/contents#create-or-update-file-contents", "status": "422"}
      

@haesleinhuepf
Copy link
Copy Markdown
Owner

Hi @sebi06 ,

would you mind trying this branch out and check if it works with your azure setup? You can install it after cloning with pip install -e . from the root directory of the repository. Note, also the installation instructions were updated and should fit your scenario very well: https://github.com/haesleinhuepf/bia-bob/blob/a92b661a26de24035298e1f18442337b4a6216be/README.md#using- 8000 azure

Let me know if it works!

Best,
Robert

@sebi06
sebi06 commented Apr 4, 2025
Copy link
Copy Markdown

Hi @haesleinhuepf

I tried the branch but I still get errors (while using AzureOpenAI interface still works fine) . When I run the cell

client2 = OpenAI(base_url=os.environ["AZURE_OPENAI_ENDPOINT"],
                 api_key=os.environ["AZURE_OPENAI_API_KEY"])

print("\n".join([model.id for model in client2.models.list().data]))

I get the following errors:

---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
Cell In[4], line 4
      1 client2 = OpenAI(base_url=os.environ["AZURE_OPENAI_ENDPOINT"],
      2                  api_key=os.environ["AZURE_OPENAI_API_KEY"])
----> 4 print("\n".join([model.id for model in client2.models.list().data]))

File f:\Documents\anaconda3\envs\prompt-env\Lib\site-packages\openai\resources\models.py:91, in Models.list(self, extra_headers, extra_query, extra_body, timeout)
     77 def list(
     78     self,
     79     *,
   (...)     85     timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
     86 ) -> SyncPage[Model]:
     87     """
     88     Lists the currently available models, and provides basic information about each
     89     one such as the owner and availability.
     90     """
---> 91     return self._get_api_list(
     92         "/models",
     93         page=SyncPage[Model],
     94         options=make_request_options(
     95             extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
     96         ),
     97         model=Model,
     98     )

File f:\Documents\anaconda3\envs\prompt-env\Lib\site-packages\openai\_base_client.py:1291, in SyncAPIClient.get_api_list(self, path, model, page, body, options, method)
   1280 def get_api_list(
   1281     self,
   1282     path: str,
   (...)   1288     method: str = "get",
   1289 ) -> SyncPageT:
   1290     opts = FinalRequestOptions.construct(method=method, url=path, json_data=body, **options)
-> 1291     return self._request_api_list(model, page, opts)

File f:\Documents\anaconda3\envs\prompt-env\Lib\site-packages\openai\_base_client.py:1142, in SyncAPIClient._request_api_list(self, model, page, options)
   1138     return resp
   1140 options.post_parser = _parser
-> 1142 return self.request(page, options, stream=False)

File f:\Documents\anaconda3\envs\prompt-env\Lib\site-packages\openai\_base_client.py:919, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
    916 else:
    917     retries_taken = 0
--> 919 return self._request(
    920     cast_to=cast_to,
    921     options=options,
    922     stream=stream,
    923     stream_cls=stream_cls,
    924     retries_taken=retries_taken,
    925 )

File f:\Documents\anaconda3\envs\prompt-env\Lib\site-packages\openai\_base_client.py:1023, in SyncAPIClient._request(self, cast_to, options, retries_taken, stream, stream_cls)
   1020         err.response.read()
   1022     log.debug("Re-raising status error")
-> 1023     raise self._make_status_error_from_response(err.response) from None
   1025 return self._process_response(
   1026     cast_to=cast_to,
   1027     options=options,
   (...)   1031     retries_taken=retries_taken,
   1032 )

NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

@haesleinhuepf
Copy link
Copy Markdown
Owner

Would you mind building in a print statement in this line to print out model_init_kwargs and check if the values make sense? I cannot debug it, because I have no azure account beyond the github models.

@sebi06
sebi06 commented Apr 4, 2025
Copy link
Copy Markdown

Hi @haesleinhuepf

I added this:

...
if image is None:  # normal text-based prompt
        system_message = [{"role": "system", "content": system_prompt}]

        # init client
        if Context.client is None or not isinstance(
            Context.client, AzureOpenAI
        ):

            # debugging
            print(f"Model init kwargs: {model_init_kwargs}")

            Context.client = AzureOpenAI(**model_init_kwargs)
            client = Context.client
...

but this line is never hit. No print and also when I set a breakpoint ist does not stop when executing:

import os
from openai import AzureOpenAI, OpenAI
from bia_bob import bob

bob.initialize(
    endpoint="https://zdp-gpt-dev-sdc-oai-001.openai.azure.com",
    api_key=os.environ.get("AZURE_API_KEY"),
    model="gpt-4o",
)

client1 = AzureOpenAI(
    api_version=os.environ["AZURE_OPENAI_API_VERSION"],
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
)

print("\n".join([model.id for model in client1.models.list().data]))


client2 = OpenAI(
    base_url=os.environ["AZURE_OPENAI_ENDPOINT"],
    api_key=os.environ["AZURE_OPENAI_API_KEY"],
)

print("\n".join([model.id for model in client2.models.list().data]))

@haesleinhuepf
Copy link
Copy Markdown
Owner

After bob.initialize(...) you need to start a cell with %bob ... otherwise your code is not invoked. Check out this example:
https://github.com/haesleinhuepf/bia-bob/blob/main/demo/azure.ipynb

@sebi06
sebi06 commented Apr 7, 2025
Copy link
Copy Markdown

Hi @haesleinhuepf

I tried again inside a jupyter notebook but nothings printed out. But I get the error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[5], line 1
----> 1 get_ipython().run_cell_magic('bob', '', 'What is the ZEN software?\n')

File f:\Documents\anaconda3\envs\prompt-env\Lib\site-packages\IPython\core\interactiveshell.py:2542, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
   2540 with self.builtin_trap:
   2541     args = (magic_arg_s, cell)
-> 2542     result = fn(*args, **kwargs)
   2544 # The code below prevents the output from being displayed
   2545 # when using magics with decorator @output_can_be_silenced
   2546 # when the last Python token in the expression is a ';'.
   2547 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File F:\Github\bia-bob\src\bia_bob\_machinery.py:171, in bob(line, cell)
    154 supported_file_types_for_generation = [".md", ".txt", ".csv", ".yml", ".yaml", ".json", ".py"]
    156 task_selection_prompt = f"""
    157 Given the following prompt, decide which of the following types of tasks we need to perform:
    158 {TASK_TYPE_CODE_GENERATION}. Code generation: The prompt asks for code to be generated.
   (...)    169 Now, write the number of the task type into the next cell. Print the number only.
    170 """
--> 171 response = ask_llm(task_selection_prompt)
    173 try:
    174     task_type = int(response.strip().strip("\n").split(".")[0])

File F:\Github\bia-bob\src\bia_bob\_utilities.py:13, in ask_llm(prompt, image, chat_history)
     10 if chat_history is None:
     11     chat_history = []
---> 13 return generate_response(chat_history=chat_history,
     14                   image=image,
     15                   model=Context.model,
     16                   system_prompt="",
     17                   user_prompt=prompt,
     18                   vision_system_prompt="")

File F:\Github\bia-bob\src\bia_bob\_utilities.py:84, in generate_response(chat_history, image, model, system_prompt, user_prompt, vision_system_prompt)
     82 from .endpoints._googlevertex import generate_response_from_vertex_ai, generate_response_from_google_ai
     83 from .endpoints._anthropic import generate_response_from_anthropic
---> 84 from .endpoints._azure import generate_response_from_azure
     85 from .endpoints._mistral import generate_response_from_mistral
     86 from .endpoints._github_models import generate_response_from_github_models

ImportError: cannot import name 'generate_response_from_azure' from 'bia_bob.endpoints._azure' (F:\Github\bia-bob\src\bia_bob\endpoints\_azure.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Azure endpoint Using bia-bob with azure hosted OpenAI dodel

2 participants

0