Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ellmer:在 R 里轻松使用多种大语言模型 #6412

Closed
ixxmu opened this issue Feb 2, 2025 · 1 comment
Closed

ellmer:在 R 里轻松使用多种大语言模型 #6412

ixxmu opened this issue Feb 2, 2025 · 1 comment

Comments

@ixxmu
Copy link
Owner

ixxmu commented Feb 2, 2025

https://mp.weixin.qq.com/s/VCvVSC8io52bP7E9TCHifw

@ixxmu
Copy link
Owner Author

ixxmu commented Feb 2, 2025

ellmer:在 R 里轻松使用多种大语言模型 by 老俊俊的生信笔记

引言

Hadley Wickham 大神最近新上线的 R 包,提供多种大语言模型,方便在 R 里进行使用。

提供的模型:

还推荐了 python 版本的:chatlas

安装

devtools::install_github("tidyverse/ellmer")

library(ellmer)

介绍

创建一个聊天对象(注意:使用对应的模型需要提供对应的 api):

library(ellmer)

chat <- chat_openai(
  model = "gpt-4o-mini",
  system_prompt = "You are a friendly but terse assistant.",
)

交互式使用:

live_console(chat)
#> ╔════════════════════════════════════════════════════════╗
#> ║  Entering chat console. Use """ for multi-line input.  ║
#> ║  Press Ctrl+C to quit.                                 ║
#> ╚════════════════════════════════════════════════════════╝
#> >>> Who were the original creators of R?
#> R was originally created by Ross Ihaka and Robert Gentleman at the University of
#> Auckland, New Zealand.
#>
#> >>> When was that?
#> R was initially released in 1995. Development began a few years prior to that,
#> in the early 1990s.

提取 chat 进行对话:

chat$chat("What preceding languages most influenced R?")
#> R was primarily influenced by the S programming language, particularly S-PLUS.
#> Other languages that had an impact include Scheme and various data analysis
#> languages.

通过 content_image_file() 或者 content_image_url() 对图片进行对话:

chat$chat(
  content_image_url("https://www.r-project.org/Rlogo.png"),
  "Can you explain this logo?"
)
#> The logo of R features a stylized letter "R" in blue, enclosed in an oval
#> shape that resembles the letter "O," signifying the programming language's
#> name. The design conveys a modern and professional look, reflecting its use
#> in statistical computing and data analysis. The blue color often represents
#> trust and reliability, which aligns with R's role in data science.

包装成函数:

my_function <- function() {
  chat <- chat_openai(
    model = "gpt-4o-mini",
    system_prompt = "You are a friendly but terse assistant.",
  )
  chat$chat("Is R a functional programming language?")
}
my_function()
#> [1] "Yes, R supports functional programming concepts. It allows functions to
#> be first-class objects, supports higher-order functions, and encourages the
#> use of functions as core components of code. However, it also supports
#> procedural and object-oriented programming styles."

结尾

路漫漫其修远兮,吾将上下而求索。


欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群 (微信交流群需收取 20 元入群费用,一旦交费,拒不退还!(防止骗子和便于管理))


往期回顾目录


shiny 版交互式大语言模型 shiny.ollamaNature Methods 2025 年 1 月 22 卷 第 1 期Cancer Cell 2025 年 1 月 13 日 第 43 卷 第 1 期Science 2025 年 1 月 17 日 387 卷 第 6731 期使用 python 来制作 shiny AppCell|Nature|Science 期刊10年封面一览Cell 2025 年 1 月 9 日 第 188 卷 第 1 期单细胞格式转换工具一文掌握!snapATAC2 多样本整合及去批次效应CNS 科研高质量图形鉴赏(三)



@ixxmu ixxmu changed the title archive_request ellmer:在 R 里轻松使用多种大语言模型 Feb 2, 2025
@ixxmu ixxmu closed this as completed Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant