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

Make openai_organization Optional in OpenAI plugins #2585

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

Future-Outlier
Copy link
Member

@Future-Outlier Future-Outlier commented Jul 16, 2024

Tracking issue

flyteorg/flyte#3936

Why are the changes needed?

It's optional now.

How was this patch tested?

chatgpt agent: unit test, local execution, and single binary remote execution
batch agent: unit test

Help

I can't run the batch agent task in my local execution.
It will start an infinite event loop.

image
import os
from typing import Iterator

from flytekit import Secret, workflow
from flytekit.types.file import JSONLFile
from flytekit.types.iterator import JSON
from flytekitplugins.openai import BatchResult, create_batch



def jsons():
    for x in [
        {
            "custom_id": "request-1",
            "method": "POST",
            "url": "/v1/chat/completions",
            "body": {
                "model": "gpt-3.5-turbo",
                "messages": [
                    {"role": "system", "content": "You are a helpful assistant."},
                    {"role": "user", "content": "What is 2+2?"},
                ],
            },
        },
        {
            "custom_id": "request-2",
            "method": "POST",
            "url": "/v1/chat/completions",
            "body": {
                "model": "gpt-3.5-turbo",
                "messages": [
                    {"role": "system", "content": "You are a helpful assistant."},
                    {"role": "user", "content": "Who won the world series in 2020?"},
                ],
            },
        },
    ]:
        yield x

#
#
# iterator_batch = create_batch(
#     name="gpt-3.5-turbo-iterator",
#     # openai_organization="your-org",
#     secret=Secret(group="openai", key="api_key"),
# )
#
#
#
# @workflow
# def json_iterator_wf(json_vals: Iterator[JSON] = jsons()) -> BatchResult:
#     return iterator_batch(jsonl_in=json_vals)
#
#
# if __name__ == "__main__":
#     print(f"Running {__file__} main...")
#     print(f"Running json_iterator_wf() {json_iterator_wf()}")

it_batch = create_batch(
    name="gpt-3.5-turbo",
    secret=Secret(group="openai", key="api_key"),
)

file_batch = create_batch(

    name="gpt-3.5-turbo",
    openai_organization="org-NayNG68kGnVXMJ8Ak4PMgQv7",
    secret=Secret(group="openai", key="api_key"),
    is_json_iterator=False,

)


@workflow
def json_iterator_wf(json_vals: Iterator[JSON] = jsons()) -> BatchResult:

    return it_batch(jsonl_in=json_vals)


@workflow
def jsonl_wf(jsonl_file: JSONLFile = "build/data.jsonl") -> BatchResult:

    return file_batch(jsonl_in=jsonl_file)

if __name__ == "__main__":
    print(f"Running {__file__} main...")
    print(f"Running json_iterator_wf() {json_iterator_wf()}")
    print(f"Running jsonl_wf() {jsonl_wf()}")

Screenshots

chatgpt local execution and remote execution

image image

Signed-off-by: Future-Outlier <eric901201@gmail.com>
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.40%. Comparing base (097e9e8) to head (047d2e2).
Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2585       +/-   ##
===========================================
- Coverage   76.22%   45.40%   -30.82%     
===========================================
  Files         187      217       +30     
  Lines       18938    20295     +1357     
  Branches     3706     3705        -1     
===========================================
- Hits        14435     9215     -5220     
- Misses       3870    10971     +7101     
+ Partials      633      109      -524     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

samhita-alla
samhita-alla previously approved these changes Jul 17, 2024
Signed-off-by: Future-Outlier <eric901201@gmail.com>
@Future-Outlier Future-Outlier merged commit 262f6d6 into master Jul 17, 2024
47 of 48 checks passed
mao3267 pushed a commit to mao3267/flytekit that referenced this pull request Jul 29, 2024
* use openai_organization: Optional[str] =  in OpenAI plugins

Signed-off-by: Future-Outlier <eric901201@gmail.com>

* change default value to None

Signed-off-by: Future-Outlier <eric901201@gmail.com>

---------

Signed-off-by: Future-Outlier <eric901201@gmail.com>
Signed-off-by: mao3267 <chenvincent610@gmail.com>
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.

2 participants