airflow.providers.openai.hooks.openai
¶
Module Contents¶
Classes¶
Use OpenAI SDK to interact with OpenAI APIs. |
- class airflow.providers.openai.hooks.openai.OpenAIHook(conn_id=default_conn_name, *args, **kwargs)[source]¶
Bases:
airflow.hooks.base.BaseHook
Use OpenAI SDK to interact with OpenAI APIs.
- Parameters
conn_id (str) – OpenAI connection id
- create_chat_completion(messages, model='gpt-3.5-turbo', **kwargs)[source]¶
Create a model response for the given chat conversation and returns a list of chat completions.
- Parameters
messages (list[openai.types.chat.ChatCompletionSystemMessageParam | openai.types.chat.ChatCompletionUserMessageParam | openai.types.chat.ChatCompletionAssistantMessageParam | openai.types.chat.ChatCompletionToolMessageParam | openai.types.chat.ChatCompletionFunctionMessageParam]) – A list of messages comprising the conversation so far
model (str) – ID of the model to use
- create_assistant(model='gpt-3.5-turbo', **kwargs)[source]¶
Create an OpenAI assistant using the given model.
- Parameters
model (str) – The OpenAI model for the assistant to use.
- get_assistant(assistant_id)[source]¶
Get an OpenAI assistant.
- Parameters
assistant_id (str) – The ID of the assistant to retrieve.
- modify_assistant(assistant_id, **kwargs)[source]¶
Modify an existing Assistant object.
- Parameters
assistant_id (str) – The ID of the assistant to be modified.
- delete_assistant(assistant_id)[source]¶
Delete an OpenAI Assistant for a given ID.
- Parameters
assistant_id (str) – The ID of the assistant to delete.
- delete_thread(thread_id)[source]¶
Delete an OpenAI thread for a given thread_id.
- Parameters
thread_id (str) – The ID of the thread to delete.
- get_messages(thread_id, **kwargs)[source]¶
Return a list of messages for a given Thread.
- Parameters
thread_id (str) – The ID of the thread the messages belong to.
- modify_message(thread_id, message_id, **kwargs)[source]¶
Modify an existing message for a given Thread.
- Parameters
thread_id (str) – The ID of the thread to which this message belongs.
message_id – The ID of the message to modify.
- create_run(thread_id, assistant_id, **kwargs)[source]¶
Create a run for a given thread and assistant.
- create_run_and_poll(thread_id, assistant_id, **kwargs)[source]¶
Create a run for a given thread and assistant and then polls until completion.
- get_runs(thread_id, **kwargs)[source]¶
Return a list of runs belonging to a thread.
- Parameters
thread_id (str) – The ID of the thread the run belongs to.
- create_embeddings(text, model='text-embedding-ada-002', **kwargs)[source]¶
Generate embeddings for the given text using the given model.
- upload_file(file, purpose)[source]¶
Upload a file that can be used across various endpoints. The size of all the files uploaded by one organization can be up to 100 GB.
- Parameters
file (str) – The File object (not file name) to be uploaded.
purpose (Literal[fine-tune, assistants]) – The intended purpose of the uploaded file. Use “fine-tune” for Fine-tuning and “assistants” for Assistants and Messages.
- get_file(file_id)[source]¶
Return information about a specific file.
- Parameters
file_id (str) – The ID of the file to use for this request.
- delete_file(file_id)[source]¶
Delete a file.
- Parameters
file_id (str) – The ID of the file to be deleted.
- get_vector_store(vector_store_id)[source]¶
Retrieve a vector store.
- Parameters
vector_store_id (str) – The ID of the vector store to retrieve.
- modify_vector_store(vector_store_id, **kwargs)[source]¶
Modify a vector store.
- Parameters
vector_store_id (str) – The ID of the vector store to modify.
- delete_vector_store(vector_store_id)[source]¶
Delete a vector store.
- Parameters
vector_store_id (str) – The ID of the vector store to delete.
- upload_files_to_vector_store(vector_store_id, files)[source]¶
Upload files to a vector store and poll until completion.
- get_vector_store_files(vector_store_id)[source]¶
Return a list of vector store files.
- Parameters
vector_store_id (str) –