Spaces:
Sleeping
Sleeping
Download examples/techniques/phi3.py from LVKinyanjui/QueryYourDocs: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/LVKinyanjui/QueryYourDocs/resolve/main/examples/techniques/phi3.py
- Command line
-
hf download hf://spaces/LVKinyanjui/QueryYourDocs/examples/techniques/phi3.py
-
curl -L -o phi3.py https://huggingface.co/spaces/LVKinyanjui/QueryYourDocs/resolve/main/examples/techniques/phi3.py
1.27 kB
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline | |
| torch.random.manual_seed(0) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| "microsoft/Phi-3-mini-4k-instruct", | |
| # device_map="auto", | |
| torch_dtype="auto", | |
| trust_remote_code=True, | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct") | |
| messages = [ | |
| {"role": "system", "content": "You are a helpful AI assistant."}, | |
| {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"}, | |
| {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."}, | |
| {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"}, | |
| ] | |
| pipe = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| ) | |
| generation_args = { | |
| "max_new_tokens": 500, | |
| "return_full_text": False, | |
| "temperature": 0.0, | |
| "do_sample": False, | |
| } | |
| output = pipe(messages, **generation_args) | |
| print(output[0]['generated_text']) | |