(model_name, prompt, temperature, top_p, max_new_tokens)
| 144 | |
| 145 | |
| 146 | def anthropic_api_stream_iter(model_name, prompt, temperature, top_p, max_new_tokens): |
| 147 | import anthropic |
| 148 | |
| 149 | c = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"]) |
| 150 | |
| 151 | # Make requests |
| 152 | gen_params = { |
| 153 | "model": model_name, |
| 154 | "prompt": prompt, |
| 155 | "temperature": temperature, |
| 156 | "top_p": top_p, |
| 157 | "max_new_tokens": max_new_tokens, |
| 158 | } |
| 159 | logger.info(f"==== request ====\n{gen_params}") |
| 160 | |
| 161 | res = c.completions.create( |
| 162 | prompt=prompt, |
| 163 | stop_sequences=[anthropic.HUMAN_PROMPT], |
| 164 | max_tokens_to_sample=max_new_tokens, |
| 165 | temperature=temperature, |
| 166 | top_p=top_p, |
| 167 | model=model_name, |
| 168 | stream=True, |
| 169 | ) |
| 170 | text = "" |
| 171 | for chunk in res: |
| 172 | text += chunk.completion |
| 173 | data = { |
| 174 | "text": text, |
| 175 | "error_code": 0, |
| 176 | } |
| 177 | yield data |
| 178 | |
| 179 | |
| 180 | def gemini_api_stream_iter( |
no outgoing calls
no test coverage detected
searching dependent graphs…