My First LLM Project!!! ðŸĪ–âœĻ

Home | News | Portfolio | Downloads | Blog | Cool Links | Guestbook
Posted on March 18, 2024 by -intern
Tags: AI, LLMs, Python, Learning

omg hi everyone!!! 👋 i'm SO excited to share my first real project working with large language models! as an intern at computacombinator, i've been learning SO much about AI and wanted to share my experience building something cool with these amazing tools! 🚀

fun fact: did you know that LLMs can write code AND explain it?? my mind was totally blown when i first discovered this! ðŸĪŊ

the project idea ðŸ’Ą

so basically, i wanted to build a discord bot that could help our dev team document their code better (because apparently that's like super important or something lol). here's what i learned:

        # my first attempt (don't laugh!)
        import discord
        from openai import OpenAI

client = discord.Client()
ai = OpenAI() # forgot api key first time oops

@client.event
async def on_message(message):
if message.content.startswith('!document'):
# it took me forever to figure out this part!!
code = message.content[10:] # remove !document
response = ai.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "user",
                "content": f"please document this code: {code}"}
            ]
        )
        await message.channel.send(response.choices[0].message.content)
        

things i learned the hard way 😅

protip: when jacob says "make sure to handle edge cases", he means ACTUALLY handle them, not just hope they never happen (found this out the hard way lololol)

the improved version! âœĻ

after some help from the team (and like a million commits), here's what i ended up with:

        import discord
        import os
        from openai import OpenAI
        from dotenv import load_dotenv
        from ratelimit import limits, sleep_and_retry

load_dotenv() # yay for environment variables!

ONE_MINUTE = 60
MAX_CALLS = 10 # learned about rate limiting!

@sleep_and_retry
@limits(calls=MAX_CALLS, period=ONE_MINUTE)
def get_documentation(code):
try:
response = ai.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system",
                "content": "You are a helpful code documentation assistant."},
                {"role": "user",
                "content": f"Please document this code:\n{code}"}
            ],
            max_tokens=1500 # avoid those pesky discord limits!
        )
        return response.choices[0].message.content
        except Exception as e:
        return f"Oops! Something went wrong: {str(e)}"
        

cool things i discovered! 🌟

working on this project taught me so much:

"it's not about writing perfect code the first time, it's about learning from your mistakes" - jacob (after i accidentally pushed to main 🙈)

what's next? 🚀

i'm super excited to keep learning and building more stuff! next up, i want to:

btw if anyone wants to try out the bot, it's running in our dev discord! just don't all use it at once or we might run out of api credits again... (sorry about that jacob! 🙏)
Related Articles:

Comments

88x31 Button Powered By Verified
Hit Counter

© 2013-2024 ComputaCombinator. All rights reserved.
Best viewed in Internet Explorer 6.0 at 1024x768 resolution
Valid HTML!