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

Add initial prototype supporting the files API #249

Merged
merged 14 commits into from
Mar 26, 2024

Conversation

MarkDaoust
Copy link
Collaborator

@MarkDaoust MarkDaoust commented Mar 22, 2024

WIP

When this is done, the code below should work

pip install -U git+https://github.com/MarkDaoust/generative-ai-python@files
pip install -U git+https://github.com/google-generativeai-python
import google.generativeai as genai

genai.configure(api_key="...")

f = genai.upload_file(path="image.png")

m = genai.GenerativeModel(model_name="models/gemini-1.5-pro")
response = m.generate_content(["hello? Pleasecdescribe this file:", f])

print(response.text)

@MarkDaoust MarkDaoust requested a review from a team as a code owner March 22, 2024 23:37
@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:python sdk Issue/PR related to Python SDK labels Mar 22, 2024
@MarkDaoust MarkDaoust marked this pull request as draft March 22, 2024 23:37
google/generativeai/client.py Outdated Show resolved Hide resolved
request = googleapiclient.http.HttpRequest(
http=httplib2.Http(),
postproc=lambda resp, content: (resp, content),
uri=f"https://{end_point}/$discovery/rest?version=v1beta&labels=GOOGLE_INTERNAL&key={api_key}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove: &labels=GOOGLE_INTERNAL. Also, should we always point to generativelanguage.googleapis.com here?

Copy link
Collaborator Author

@MarkDaoust MarkDaoust Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&labels=GOOGLE_INTERNAL

Done.

always point to

If they override the endpoint shouldn't we respect that? I can't really test this code without that.

google/generativeai/client.py Outdated Show resolved Hide resolved
google/generativeai/client.py Outdated Show resolved Hide resolved
google/generativeai/types/content_types.py Outdated Show resolved Hide resolved
@MarkDaoust MarkDaoust requested a review from markmcd March 25, 2024 18:02
@MarkDaoust MarkDaoust marked this pull request as ready for review March 25, 2024 23:30
@MarkDaoust MarkDaoust merged commit 8475b9f into google-gemini:main Mar 26, 2024
7 checks passed
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label Mar 26, 2024
@Qxxxx
Copy link

Qxxxx commented Mar 27, 2024

Hi @MarkDaoust, thanks for this api. That would be helpful. Though I meet the following error:

Traceback (most recent call last):
  File "/Users/qiguang/gemini_init/test.py", line 5, in <module>
    f = genai.upload_file(path="IMG_0521.PNG")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/qiguang/miniconda3/envs/pytorch/lib/python3.11/site-packages/google/generativeai/files.py", line 49, in upload_file
    response = client.create_file(
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/qiguang/miniconda3/envs/pytorch/lib/python3.11/site-packages/google/generativeai/client.py", line 75, in create_file
    result = request.execute()
             ^^^^^^^^^^^^^^^^^
  File "/Users/xxxx/miniconda3/envs/pytorch/lib/python3.11/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/qiguang/miniconda3/envs/pytorch/lib/python3.11/site-packages/googleapiclient/http.py", line 938, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 501 when requesting https://generativelanguage.googleapis.com/upload/v1beta/files?key=AIzaSyA8mR0GDyiha1hN1j0llZ7VoRWlWy6fQEA&alt=json&uploadType=multipart returned "Endpoint not implemented.". Details: "Endpoint not implemented.">

Also, does it means it support type: application/pdf now? Though it could by uploading pdf to aistudio, but api wise I don't know how to do it. That would be nice if you could help me with this issue! Thanks in advance!

@TYMichaelChen
Copy link
Contributor

Hi @Qxxxx - The API is currently in private preview, so that error is expected.

We will not support PDFs via the API. I would recommend taking a look at LlamaIndex for pdf parsing on the client side

@Qxxxx
Copy link

Qxxxx commented Mar 28, 2024

Thanks a lot, this repo is very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants