START OF PREVIOUS DISCUSSION user:from huggingfacehub import InferenceClient client =…
- User
START OF PREVIOUS DISCUSSION user:from huggingface_hub import InferenceClient
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1") for token in client.text_generation("Tell me a huge story", stream=True, max_new_tokens=1024, ): print(token)
is it possible to avoid it caching the values? robot:If your concern is about the response getting cached and affecting subsequent requests, using the InferenceClient from huggingface_hub as shown does not inherently cache responses between separate executions of your Python script. Each time you run your script, a new request is issued to the model endpoint, and the generated text should be unique to that request unless the model produces a deterministic response for the same prompt.However, if you’re referring to the behavior where printed outputs remain on your console or in your environment, those are not cached by the InferenceClient but are merely a consequence of how the standard output stream works. The print function will output content to the console or wherever your standard output is directed, and each token received from the stream will be printed in sequential order. If you want to avoid printing each token or want to handle outputs differently, you would need to manage that in your code.For instance, if you wanted to consolidate the output tokens into a single story and then clear it before generating a new one, you would need to store the tokens in a variable and control when to print or clear that variable. Here’s an example:from huggingface_hub import InferenceClient# Initialize the clientclient = InferenceClient(“mistralai/Mixtral-8x7B-Instruct-v0.1”)# Container for the storystory = “”# Generate a huge storyfor token in client.text_generation(“Tell me a huge story”, stream=True, max_new_tokens=1024): story += token[“generated_text”]# Print the entire storyprint(story)# Clear the story before generating a new onestory = “”However, this is a simplistic approach. Depending on your requirements, you might also need to consider other factors such as processing time or rate limits that APIs might have if making frequent requests to the service. Remember, the actual management of unique sessions and maintaining state between them would have to be handled on the server-side (by Hugging Face’s APIs in this case) or managed through your client-side code logic. END OF PREVIOUS DISCUSSION user: @app.post("/get_talk") async def get_talk_endpoint(data: RequestData): try: for response in smixtral8x7.bot.ask(data.history): yield response except Exception as e: raise HTTPException(status_code=500, detail=str(e))
do u think this will work?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.