Skip to content

Forum in maintenance, we will back soon πŸ™‚

How To Create AI To...
 
Notifications
Clear all

How To Create AI Tools Fast (Less Than 2 Minutes)

17 Posts
3 Users
4 Reactions
55 Views
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

@zimbaboxΒ 

'''From File: llm.py'''

def llm_generate_text(prompt, service, model):
    if service == "OpenAI":
        generated_text = openai_generate(prompt, model)
    elif service == "NlpCloud":
        generated_text = nlp_cloud_generate(prompt, model)
    elif service == "Cohere":
        generated_text = cohere_generate(prompt, model)

    return generated_text


# Open AI Function
openai.api_key = "sk-XXX"


def openai_generate(user_prompt, selected_model):
    completion = openai.chat.completions.create(
        model=selected_model, messages=[{"role": "user", "content": user_prompt}]
    )
    return completion.choices[0].message.content

Β Then you use one of "OpenAI", "NlpCloud" or "Cohere" for the service parameter. For the model you need one of the ones mentioned in the documentation at https://platform.openai.com/docs/guides/text-generation .

'''file: app.py'''

import llm

prompt = "What is AI prompt engineering?"
result = llm.llm_generate_text(prompt, "OpenAI", "gpt-3.5-turbo")
print result.

Β You can find the course codes at https://github.com/hassancs91/PE-Course-codes

This post was modified 1 year ago by SSAdvisor

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 12/20/2023 7:00 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

@zimbabox why you can't find the code?Β 

here it is:

PE-Course-codes/llm.py at main Β· hassancs91/PE-Course-codes (github.com)

 
Posted : 12/20/2023 7:13 pm
Omar reacted
Page 2 / 2
Share:
[the_ad_group id="312"]