(
messages: List[Dict[str, str]],
temperature: int = 0,
model: str = "gpt-3.5-turbo",
scope: str = "USA",
purpose: str = "Generic",
session_id: str = None,
# model: str = "gpt-4",
)
| 70 | return assistant_message |
| 71 | |
| 72 | def call_chat( |
| 73 | messages: List[Dict[str, str]], |
| 74 | temperature: int = 0, |
| 75 | model: str = "gpt-3.5-turbo", |
| 76 | scope: str = "USA", |
| 77 | purpose: str = "Generic", |
| 78 | session_id: str = None, |
| 79 | # model: str = "gpt-4", |
| 80 | ): |
| 81 | |
| 82 | start = time.time() |
| 83 | try: |
| 84 | res = openai.ChatCompletion.create( |
| 85 | model=model, |
| 86 | temperature=temperature, |
| 87 | messages=messages |
| 88 | ) |
| 89 | except Exception as e: |
| 90 | duration = time.time() - start |
| 91 | log_apicall( |
| 92 | duration, |
| 93 | 'openai', |
| 94 | model, |
| 95 | 0, |
| 96 | 0, |
| 97 | scope, |
| 98 | purpose, |
| 99 | session_id = session_id, |
| 100 | success=False, |
| 101 | log_message = str(e), |
| 102 | ) |
| 103 | raise e |
| 104 | |
| 105 | duration = time.time() - start |
| 106 | |
| 107 | usage = res['usage'] |
| 108 | input_tokens = usage['prompt_tokens'] |
| 109 | output_tokens = usage['completion_tokens'] |
| 110 | |
| 111 | log_apicall( |
| 112 | duration, |
| 113 | 'openai', |
| 114 | model, |
| 115 | input_tokens, |
| 116 | output_tokens, |
| 117 | scope, |
| 118 | purpose, |
| 119 | session_id = session_id, |
| 120 | ) |
| 121 | |
| 122 | # completion = res['choices'][0]["message"]["content"] |
| 123 | assistant_message = res['choices'][0]['message']['content'] |
| 124 | |
| 125 | return assistant_message |
| 126 | |
| 127 | def clean_sql_message_content(assistant_message_content): |
| 128 | """ |
no test coverage detected