Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 12, 2024
1 parent 871a528 commit c8c1167
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 54 deletions.
3 changes: 2 additions & 1 deletion R/chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ ghost_chat <- function(service = getOption("gpttools.service", "openai"),
Here is the context:

Check warning on line 157 in R/chat.R

View check run for this annotation

Codecov / codecov/patch

R/chat.R#L157

Added line #L157 was not covered by tests
{context$above}
{context$below}")
{context$below}"

Check warning on line 160 in R/chat.R

View check run for this annotation

Codecov / codecov/patch

R/chat.R#L159-L160

Added lines #L159 - L160 were not covered by tests
)

stream_chat(
prompt = instructions,
Expand Down
107 changes: 54 additions & 53 deletions R/stream-chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ stream_chat <- function(prompt,
output_id = "streaming",
where = "console") {
switch(service,
"openai" = {
response <- stream_chat_openai(
prompt = prompt,
element_callback = create_handler("openai", r, output_id, where)
)
},
"anthropic" = {
response <- stream_chat_anthropic(
prompt = prompt,
element_callback = create_handler("anthropic", r, output_id, where)
)
},
"perplexity" = {
response <- stream_chat_perplexity(
prompt = prompt,
element_callback = create_handler("perplexity", r, output_id, where)
)
},
"cohere" = {
response <- stream_chat_cohere(
prompt = prompt,
element_callback = create_handler("cohere", r, output_id, where)
)
},
"ollama" = {
response <- stream_chat_ollama(
prompt = prompt,
element_callback = create_handler("ollama", r, output_id, where)
)
}
"openai" = {
response <- stream_chat_openai(
prompt = prompt,
element_callback = create_handler("openai", r, output_id, where)

Check warning on line 10 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L10

Added line #L10 was not covered by tests
)
},
"anthropic" = {
response <- stream_chat_anthropic(
prompt = prompt,
element_callback = create_handler("anthropic", r, output_id, where)

Check warning on line 16 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L16

Added line #L16 was not covered by tests
)
},
"perplexity" = {
response <- stream_chat_perplexity(
prompt = prompt,
element_callback = create_handler("perplexity", r, output_id, where)

Check warning on line 22 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L22

Added line #L22 was not covered by tests
)
},
"cohere" = {
response <- stream_chat_cohere(
prompt = prompt,
element_callback = create_handler("cohere", r, output_id, where)

Check warning on line 28 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L28

Added line #L28 was not covered by tests
)
},
"ollama" = {
response <- stream_chat_ollama(
prompt = prompt,
element_callback = create_handler("ollama", r, output_id, where)

Check warning on line 34 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L34

Added line #L34 was not covered by tests
)
}
)
}

Expand Down Expand Up @@ -81,8 +81,9 @@ create_handler <- function(service = "openai",
cat(parsed)
} else if (where == "source") {
rlang::check_installed("rstudioapi",
version = "0.15.0.9",
action = \(pkg, ...) pak::pak("rstudio/rstudioapi"))
version = "0.15.0.9",
action = \(pkg, ...) pak::pak("rstudio/rstudioapi")

Check warning on line 85 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L79-L85

Added lines #L79 - L85 were not covered by tests
)
rstudioapi::setGhostText(env$full_resp)

Check warning on line 87 in R/stream-chat.R

View check run for this annotation

Codecov / codecov/patch

R/stream-chat.R#L87

Added line #L87 was not covered by tests
}

Expand All @@ -95,27 +96,27 @@ create_handler <- function(service = "openai",

get_stream_pattern <- function(service) {
switch(service,
"openai" = {
pattern <- '\\{"id":.*?\\}\\]\\}'
pluck <- c("choices", "delta", "content")
},
"anthropic" = {
pattern <- "\\{\"type\":\"completion\",.*\"log_id\":\"compl_[^\"]*\"\\}"
pluck <- "completion"
},
"perplexity" = {
pattern <- '\\{"id".*?\\}\\}\\]\\}'
pluck <- c("choices", "delta", "content")
},
"cohere" = {
pattern <-
'\\{"is_finished":false,"event_type":"text-generation","text":".*"\\}'
pluck <- "text"
},
"ollama" = {
pattern <- '\\{"model":.*"done":false\\}'
pluck <- "response"
}
"openai" = {
pattern <- '\\{"id":.*?\\}\\]\\}'
pluck <- c("choices", "delta", "content")
},
"anthropic" = {
pattern <- "\\{\"type\":\"completion\",.*\"log_id\":\"compl_[^\"]*\"\\}"
pluck <- "completion"
},
"perplexity" = {
pattern <- '\\{"id".*?\\}\\}\\]\\}'
pluck <- c("choices", "delta", "content")
},
"cohere" = {
pattern <-
'\\{"is_finished":false,"event_type":"text-generation","text":".*"\\}'
pluck <- "text"
},
"ollama" = {
pattern <- '\\{"model":.*"done":false\\}'
pluck <- "response"
}
)
list(pattern = pattern, pluck = pluck)
}

0 comments on commit c8c1167

Please sign in to comment.