Create ollama_with_python.py
This commit is contained in:
		
							
								
								
									
										10
									
								
								2024.12.11_ollama/ollama_with_python.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								2024.12.11_ollama/ollama_with_python.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| # 直接输出 | ||||
| import ollama | ||||
| response = ollama.chat(model="llama3.2:latest", messages=[{"role": "user","content": "你好"}], stream=False) | ||||
| print(response['message']['content']) | ||||
|  | ||||
| # 流式输出 | ||||
| import ollama | ||||
| response = ollama.chat(model="llama3.2:latest", messages=[{"role": "user", "content": "你好"}], stream=True) | ||||
| for part in response: | ||||
|     print(part['message']['content'], end='', flush=True) | ||||
		Reference in New Issue
	
	Block a user