MCPcopy
hub / github.com/lm-sys/FastChat / anthropic_api_stream_iter

Function anthropic_api_stream_iter

fastchat/serve/api_provider.py:146–177  ·  view source on GitHub ↗
(model_name, prompt, temperature, top_p, max_new_tokens)

Source from the content-addressed store, hash-verified

144
145
146def 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
180def gemini_api_stream_iter(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…