OpenAI
Generates texts with using the OpenAI Batch API.
OpenAIClient
Bases: BatchClient
Source code in dactyl_generation/openai_generation.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__init__(api_key)
Constructor for OpenAI Client key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
OpenAI API key. |
required |
Source code in dactyl_generation/openai_generation.py
16 17 18 19 20 21 22 23 24 25 | |
create_batch_job(prompts_df)
Creates batch job of prompts given messages and temperatures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts_df
|
DataFrame
|
DataFrame where each row corresponds to an OpenAI API call. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict
|
dictionary containing request information |
Source code in dactyl_generation/openai_generation.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
create_individual_request(custom_id, message_body)
staticmethod
Creates OpenAI REST API request for a single request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_id
|
str
|
Custom ID of request |
required |
message_body
|
dict
|
dictionary of a single message. This includes the messages, max_completion_token parameters etc. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
request |
dict
|
individual request formatted for OpenAI REST API. |
Source code in dactyl_generation/openai_generation.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
get_batch_job_output(file_path)
Gets batch job results using saved metadata from a local JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
local JSON file containing output of the |
required |
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
pandas DataFrame of generations. |
Source code in dactyl_generation/openai_generation.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |