#๐Ÿ”’ trying to run llama3 on python

22 messages ยท Page 1 of 1 (latest)

robust sundialBOT
#

@west halo

Python help channel opened

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.

west halo
#
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>

surreal chasm
west halo
surreal chasm
#

!resources below have lots of good beginner level material

robust sundialBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

surreal chasm
#

Out of which, Byte of Python and Automate the Boring Stuff are usually recommended. But you do you.

west halo
#

ok thanks but do you know where can be problem in the code?

surreal chasm
west halo
#

ok thanks

surreal chasm
#

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.

west halo
#

ok thanks i will try to learn it

surreal chasm
west halo
#

thanks

robust sundialBOT
#
Python help channel closed

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.