#๐ trying to run llama3 on python
22 messages ยท Page 1 of 1 (latest)
@west halo
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import time
def start_llama3():
process = subprocess.Popen(
['ollama', 'run', 'llama3'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
return process
# sending question to the llama 3 and reecievig answer
def send_to_llama3(process, user_input):
output, error = process.communicate(input=user_input)
if error:
print(f"Chyba: {error}")
return output
def main():
llama_process = start_llama3()
# Allow some time for the process to initialize
time.sleep(2)
while True:
user_input = input("enter input or use exit to exit: ")
if user_input.lower() == 'exit':
break
print("Please wait...")
llama_response = send_to_llama3(llama_process, user_input)
print("Odpovฤฤ LLaMA 3:", llama_response)
llama_process.terminate() # end llama3 process
if __name__ == "__main__":
main() ```
PS C:\Users\Domino\Desktop\projekty\pyaiface> & 'c:\Users\Domino\AppData\Local\Microsoft\WindowsApps\python3.9.exe' 'c:\Users\Domino\debugpy\launcher' '63127' '--' 'c:\Users\Domino\Desktop\projekty\pyaiface\import subprocess.py'
enter input or use exit to exit: hi
Please wait...
Odpovฤฤ LLaMA 3: Hi! It's nice to meet you. Is there something I can help you with, or would you like to chat?
Traceback (most recent call last):
File "c:\Users\Domino\Desktop\projekty\pyaiface\import subprocess.py", line 41, in <module>
main()
File "c:\Users\Domino\Desktop\projekty\pyaiface\import subprocess.py", line 34, in main
llama_response = send_to_llama3(llama_process, user_input)
File "c:\Users\Domino\Desktop\projekty\pyaiface\import subprocess.py", line 16, in send_to_llama3
output, error = process.communicate(input=user_input)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1109,
in communicate
raise ValueError("Cannot send input after starting communication")
ValueError: Cannot send input after starting communication
PS C:\Users\Domino\Desktop\projekty\pyaiface>
thats a weird way to use ollama. Why not use langchain?
Lots of tutorials on how to do this @west halo https://python.langchain.com/docs/tutorials/
But you have to swap out parts where it says OpenAI for Ollama. Like this https://python.langchain.com/api_reference/ollama/llms/langchain_ollama.llms.OllamaLLM.html#ollamallm
thanks i dont know why im using longchain becouse GPT told me to becouse i dont know much how to use python but the whole code looks like this https://paste.pythondiscord.com/QCYA
Well... I guess you have to properly learn Python first before you try to integrate to Ollama's llama3 model.
!resources below have lots of good beginner level material
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
Out of which, Byte of Python and Automate the Boring Stuff are usually recommended. But you do you.
ok thanks but do you know where can be problem in the code?
Yes. You're not using Langchain and you don't know Python. Learn Python, get the basics down, and then use Langchain.
ok thanks
Don't jump to the end. Walk your way towards it properly
And lastly, don't use ChatGPT. As you can tell, it doesn't work.
ok thanks i will try to learn it
When you do get stuck learning it, please ask. All of us here will support you in your learning journey. ๐ All the best!
thanks
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.