Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure OpenAI backend #13

Open
jpoullet2000 opened this issue May 22, 2023 · 4 comments
Open

Azure OpenAI backend #13

jpoullet2000 opened this issue May 22, 2023 · 4 comments

Comments

@jpoullet2000
Copy link

Hi,
Would you be interested if I PR an Azure OpenAI backend?

@bluecoconut
Copy link
Contributor

For sure!

I welcome any and all contributions~

@jpoullet2000
Copy link
Author

I have a working Azure OpenAI backend manually tested with this code snippet

import pandas as pd
import os
import sketch

# Configure Azure-OpenAI
os.environ["SKETCH_USE_REMOTE_LAMBDAPROMPT"] = "False"
os.environ['LAMBDAPROMPT_BACKEND'] = 'Azure-OpenAI'
os.environ['OPENAI_API_KEY'] = my_api_key
os.environ['OPENAI_API_URL']="https://mygpt4.openai.azure.com/"
os.environ['OPENAI_API_VERSION']="2023-03-15-preview" 
os.environ['OPENAI_MODEL']="GPT4-32k"

# Sample DataFrame
df = pd.DataFrame({
    "country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
    "gdp": [19294482071552, 2891615567872, 2411255037952, 3435817336832, 1745433788416, 1181205135360, 1607402389504, 1490967855104, 4380756541440, 14631844184064],
    "happiness_index": [6.94, 7.16, 6.66, 7.07, 6.38, 6.4, 7.23, 7.22, 5.87, 5.12]
})

df.sketch.ask("Which are the European countries?")

which returns The European countries in the dataframe are United Kingdom, France, Germany, and Italy. as expected.

df.sketch.howto("How to get the top 3 happiest countries?")

returns

# First, sort the dataframe by the happiness_index column in descending order
sorted_df = df.sort_values(by='happiness_index', ascending=False)

# Then, select the top 3 rows of the sorted dataframe
top_3_happiest_countries = sorted_df.head(3)

# Display the results
print(top_3_happiest_countries)

I have a few comments/questions though:

  • the current implementation is limited to GPT4, I'm not planning to use GPT3 anymore. However, you might want to have different versions working (if not GPT3, maybe GPT5 in a few months)... how would you manage that ? I feel like it is not structurally available in the package right now.
  • I don't give freedom yet to change role/content in the message. Any suggestion there ? See here.
  • I have not created a lambdaprompt/gpt4.py since I did not want to mess up with your current implementation. However, I guess this should be done.
  • about testing, do you have any suggestions of tests. The backends are not directly tested in your test suite.

@bluecoconut
Copy link
Contributor

Sorry about the late response here. I really appreciate the work you're doing!!

the current implementation is limited to GPT4, I'm not planning to use GPT3 anymore. However, you might want to have different versions working (if not GPT3, maybe GPT5 in a few months)... how would you manage that ? I feel like it is not structurally available in the package right now.

Maybe making subclasses of the OpenAICompletion with the model set

class OpenAIGPT4Completion(OpenAICompletion)
def __init__(self, *args, **kwargs):
    super().__init__(self, *args, model='gpt-4', **kwargs)

and then adding keywords to the set-backend to offer Env-var settings to chose?

  1. The Chat style interface (with the .messages) when a backend is used as chat-style, offers templated vaiables as well. Here's the example of the Chat style backend
    class OpenAIChat(OpenAICompletion):

    Note that in this the messages concept is actually used with template variables
    async def function(user_input=None, **prompt_kwargs):

This means that you can leave variables in there, such as {{system_message}} and then in future use call things like chat = Chat(model='gpt-4').add(system="{{system_message}}") and then chat("Who are you?", system_message="Answer like a pirate?")
Not sure if that answers the question, but that's how i introduce freedom at the lambdaprompt level to change the structure of prompt. (there's a different level answre for how to integrate this at the sketch level though)

  1. I was planning on deleting gpt3.py at some point, but kept it for backwards compatibility. That said, maybe it'd be good to create an openai.py and put everything that's a specific model there in that file? I'm open to whatever

  2. No, i skipped tests when i made the backends even though i probably should have done something. It's a gap, since the rest of lambdaprompt was pretty well tested. I didn't want to bring in the overhead of transformers package and such into tests so I didn't know the best way to test this.

Note, the OpenAI implementations are tested though, via patching the http request part -> https://github.com/approximatelabs/lambdaprompt/blob/main/tests/test_gpt3.py

Maybe something like this is best way to go for testing.

@bluecoconut
Copy link
Contributor

Also, feel free to open up a PR, it'll be easier to iterate on code feedback there~

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

No branches or pull requests

2 participants