Skip to content

Instantly share code, notes, and snippets.

@JAICHANGPARK
Last active May 18, 2025 00:08
Show Gist options
  • Save JAICHANGPARK/da30af4dcdf2684fa789fa6eae3d6622 to your computer and use it in GitHub Desktop.
Save JAICHANGPARK/da30af4dcdf2684fa789fa6eae3d6622 to your computer and use it in GitHub Desktop.
BWAI for everyone - hands-on : langchain
GOOGLE_API_KEY=
if err := godotenv.Load(); err != nil {
log.Fatal("No .env file found")
}
// Loads the API Key from environment
// Loads the API key from environment
apiKey := os.Getenv("GOOGLE_API_KEY")
if apiKey == "" {
log.Fatal("Set your GOOGLE_API_KEY environment variable in the .env file")
}
package main
import (
"context"
"log"
"os"
"github.com/joho/godotenv"
"github.com/tmc/langchaingo/chains"
"github.com/tmc/langchaingo/llms/googleai"
"github.com/tmc/langchaingo/prompts"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal("No .env file found")
}
apiKey := os.Getenv("GOOGLE_API_KEY")
if apiKey == "" {
log.Fatal("Set your GOOGLE_API_KEY environment variable in the .env file")
}
ctx := context.Background()
llm, err := googleai.New(ctx, googleai.WithAPIKey(apiKey),
googleai.WithDefaultModel("gemini-2.5-flash-preview-04-17"))
if err != nil {
log.Fatal(err)
}
prompt := "strawberry에는 r이 몇개 포함되어 있는지 알아?"
completion, err := llms.GenerateFromSinglePrompt(ctx, llm, prompt)
if err != nil {
log.Fatal(err)
}
fmt.Println(completion)
}
package main
import (
"context"
"log"
"os"
"github.com/joho/godotenv"
"github.com/tmc/langchaingo/chains"
"github.com/tmc/langchaingo/llms/googleai"
"github.com/tmc/langchaingo/prompts"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal("No .env file found")
}
apiKey := os.Getenv("GOOGLE_API_KEY")
if apiKey == "" {
log.Fatal("Set your GOOGLE_API_KEY environment variable in the .env file")
}
ctx := context.Background()
llm, err := googleai.New(ctx, googleai.WithAPIKey(apiKey),
googleai.WithDefaultModel("gemini-2.5-flash-preview-04-17"))
if err != nil {
log.Fatal(err)
}
prompt := prompts.NewPromptTemplate(
`You are a helpful AI assistant:
Question: {{.question}}`,
[]string{"question"})
llmChain := chains.NewLLMChain(llm, prompt)
const question = "How do I get started genai?"
inputs := map[string]interface{}{
"question": question,
}
out, err := chains.Call(ctx, llmChain, inputs)
if err != nil {
log.Fatalf("Failed to run LLM chain: %v", err)
}
responseText, ok := out["text"].(string)
if !ok {
log.Println("Unexpected response type")
return
}
log.Println("Question:", question)
log.Println("Generated Answer:", responseText)
}
llm, err := googleai.New(ctx, googleai.WithAPIKey(apiKey),
googleai.WithDefaultEmbeddingModel("gemini-embedding-exp-03-07"))
if err != nil {
log.Fatal(err)
}
texts := []string{"딥러닝과 머신러닝의 차이", "동해물과 백두산이 마르고 닳도록"}
emb, err := llm.CreateEmbedding(ctx, texts)
if err != nil {
log.Fatal(err)
}
fmt.Println("Num of embedding vectors:", len(emb))
for i, e := range emb {
fmt.Printf("%d: %v...\n", i, e[:10])
}
@JAICHANGPARK
Copy link
Author

go run main.go
2025/05/10 12:58:45 Question: How do I get started genai?
2025/05/10 12:58:45 Generated Answer: Okay, "GenAI" stands for Generative AI. Getting started with it can mean different things depending on your goal. Here are a few common ways to approach it, from simplest to more technical:

Path 1: Just Using Existing GenAI Tools (Easiest)

  • Goal: To understand what GenAI can do by interacting with it directly.
  • How to Start:
    1. Pick a tool: Start with a popular and accessible one.
      • Text: ChatGPT (OpenAI), Gemini (Google), Claude (Anthropic), Llama (Meta - often via interfaces like Hugging Face or third-party apps).
      • Image: Midjourney, Stable Diffusion, DALL-E 3 (integrated into ChatGPT/Bing).
      • Code: GitHub Copilot, Codey (Google), various others.
      • Music/Audio: Suno, Udio, ElevenLabs (voice).
    2. Sign up: Most have free tiers or trials to get you started.
    3. Experiment: Start asking questions, writing prompts, generating images, writing code snippets.
    4. Learn Prompting: The key to getting good results is learning how to write effective prompts. There are many guides online for "prompt engineering."
  • This path is great for: Writers, artists, students, researchers, general users, or anyone curious about the capabilities without deep technical knowledge.

Path 2: Learning the Concepts Behind GenAI

  • Goal: To understand what Generative AI is, how it broadly works, its different types, and its implications.
  • How to Start:
    1. Read Articles & Watch Videos: Look for introductory explanations of terms like "Large Language Models (LLMs)," "Transformers," "Diffusion Models," "GANs," "Prompt Engineering," "Ethics in AI."
    2. Take Introductory Courses: Many platforms offer free or paid courses explaining the fundamentals of AI and GenAI (Coursera, edX, Udacity, deeplearning.ai, Udemy, DataCamp). Look for courses titled "Introduction to AI," "Generative AI Explained," etc.
    3. Follow News & Blogs: Stay updated on new models, applications, and research.
  • This path is great for: Anyone who wants a deeper understanding beyond just using the tools, including managers, policymakers, educators, and curious individuals.

Path 3: Learning to Build/Develop with GenAI

  • Goal: To create applications, workflows, or even models that use Generative AI. This requires some technical background, usually in programming.
  • How to Start:
    1. Strengthen Programming Skills: Python is the most common language in AI/ML.
    2. Learn Machine Learning Basics: Understand concepts like models, training, inference, APIs.
    3. Explore GenAI APIs: Learn how to use the APIs provided by companies like OpenAI, Google AI, Anthropic, etc., to integrate GenAI capabilities into your own applications.
    4. Learn Frameworks/Libraries: Explore tools like LangChain or LlamaIndex which help orchestrate interactions with LLMs, or delve into ML frameworks like TensorFlow or PyTorch if you want to work closer to the model level (e.g., fine-tuning).
    5. Take Development-Focused Courses: Look for courses on "Building Applications with LLMs," "Generative AI for Developers," etc.
    6. Work on Projects: Build small applications that use GenAI (e.g., a chatbot, a text summarizer, an image generator interface).
  • This path is great for: Software developers, data scientists, researchers, and engineers.

General Tips for Getting Started:

  • Define Your Goal: What do you want to do with GenAI? Use it for writing? Create art? Build a new app? This helps choose your path.
  • Start Simple: Don't try to learn everything at once. Pick one tool or one concept and go from there.
  • Experiment: Hands-on practice is crucial, whether it's writing prompts or writing code.
  • Join Communities: Online forums, Discord servers, or local meetups can be great for asking questions and learning from others.
  • Stay Curious: The field is evolving incredibly fast. Be prepared to keep learning.

Choose the path that aligns best with your interests and current skills, and just start exploring!

@JAICHANGPARK
Copy link
Author

JAICHANGPARK commented May 17, 2025

go get github.com/joho/godotenv
go get github.com/tmc/langchaingo/chains
go get github.com/tmc/langchaingo/llms/googleai
go get github.com/tmc/langchaingo/prompts

@Jeffr-K
Copy link

Jeffr-K commented May 17, 2025

재미있고 유익한 세션 감사드립니다.

질문 1) 이런 에이전트 개발 시 파이썬보다 Golang 만의 강점이 있을까요? 핸즈온 세션을 보니 성능의 문제는 추론 서버의 응답 같아서요.

질문 2) Golang 질문인데, 실무에서 프로젝트 구조화같은 협업을 위한 Go 컨벤션은 커뮤니티를 많이 따라가나요? 아니면 자체적으로 구축해서 사용하나요?

질문 3) 고랭에서 context drilling 같은 부분은 모니터링을 어떤식으로 할까요?? 자바에서는 thread local id 같은게 있다고 들었습니다.

질문 4) Eino 를 활용해서 프로젝트 하나 해보고 싶은데, 역시 에이전트 프로젝트가 나을까요?

@JAICHANGPARK
Copy link
Author

@Jeffr-K 좋은 질문 감사합니다.

질문 1) 이런 에이전트 개발 시 파이썬보다 Golang 만의 강점이 있을까요? 핸즈온 세션을 보니 성능의 문제는 추론 서버의 응답 같아서요.

Golang은 Python과 달리 컴파일 언어이기도 하고 정적 타입 언어로, 컴파일 시점에 많은 오류를 잡아낼 수 있어요. Python에 비해 일반적으로 메모리 사용량이 적고 실행 속도가 빠릅니다. 특히 동시성 처리와 메모리 관리 효율성에서 강점을 보입니다.

질문 2) Golang 질문인데, 실무에서 프로젝트 구조화같은 협업을 위한 Go 컨벤션은 커뮤니티를 많이 따라가나요? 아니면 자체적으로 구축해서 사용하나요?

질문에 대한 정답은 없다고 보네요. 널리 알려진 커뮤니티의 표준과 패턴을 적극적으로 수용하고 이해한 뒤, 팀과 프로젝트의 상황에 맞게 선택, 조합, 확장하여 내부 표준으로 발전시켜 나가는 방식이 가장 효과적이고 일반적이지 않을까 생각합니다.

질문 3) 고랭에서 context drilling 같은 부분은 모니터링을 어떤식으로 할까요?? 자바에서는 thread local id 같은게 있다고 들었습니다.

OpenTelemetry 를 활용하는 방법도 있을거 같네요.

질문 4) Eino 를 활용해서 프로젝트 하나 해보고 싶은데, 역시 에이전트 프로젝트가 나을까요?

프로젝트에서 어떤 것(What)을 구현할지 계획을 잘 정하신 뒤에 Agents가 필요한지 검토(How)해보시는 방향도 좋을거 같아요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment