🔒 Closed Patulong pano i echo each variable in php

Status
Not open for further replies.

genshin_mica

Enthusiast
Im using function po pala here's my problem.

ito yung response nya :
Code:
data: {"id": "cmpl-5k0qzLNzppeQlXrWIwrAWfK8hT5Pr", "object": "text_completion", "created": 1661648053, "choices": [{"text": "Generate a essay about covid-19\n", "index": 0, "logprobs": {"tokens": ["Gener", "ate", " a", " essay", " about", " cov", "id", "-", "19", "\n"], "token_logprobs": [null, -1.3476847, -3.0771973, -11.818048, -2.622668, -9.0709505, -0.016957467, -0.84929115, -0.18857196, -0.16325226], "top_logprobs": [null, {"ator": -1.5927457, "ators": -4.140435, "ation": -2.014184, "ate": -1.3476847, "ated": -1.0731707}, {" a": -3.0771973, " the": -3.7896504, "Token": -3.4643273, "_": -3.764857, "(": -3.3900204}, {" random": -1.7557685, " list": -2.298317, " new": -3.1648924, " report": -3.4866753, " function": -4.182503}, {"\n": -1.6765634, " of": -2.899561, " on": -1.5899266, " for": -2.7870564, " about": -2.622668}, {" the": -2.3893545, " a": -2.849516, " yourself": -3.10794, " your": -3.2955954, " myself": -3.6074443}, {"entry": -5.7374864, "in": -5.187419, "id": -0.016957467, "il": -7.4663396, "f": -7.513945}, {"19": -2.466882, "-": -0.84929115, "\n": -1.6373503, "\n\n": -4.7498336, " 19": -1.3726304}, {"19": -0.18857196, "\n": -1.7672089, "2019": -8.650725, "\n\n": -7.920331, " 19": -8.172422}, {" outbreak": -6.7257586, "\n": -0.16325226, " in": -5.3444796, " and": -6.824823, "\n\n": -2.0016062}], "text_offset": [0, 5, 8, 10, 16, 22, 26, 28, 29, 31]}, "finish_reason": null}], "model": ""}

data: {"id": "cmpl-5k0qzLNzppeQlXrWIwrAWfK8hT5Pr", "object": "text_completion", "created": 1661648053, "choices": [{"text": "\n", "index": 0, "logprobs": {"tokens": ["\n"], "token_logprobs": [-0.0013815904], "top_logprobs": [{"It": -10.35923, "\n": -0.0013815904, "C": -8.160785, "The": -9.323654, "\n\n": -7.1774726}], "text_offset": [32]}, "finish_reason": null}], "model": ""}

data: {"id": "cmpl-5k0qzLNzppeQlXrWIwrAWfK8hT5Pr", "object": "text_completion", "created": 1661648053, "choices": [{"text": "C", "index": 0, "logprobs": {"tokens": ["C"], "token_logprobs": [-0.38441458], "top_logprobs": [{"Cor": -3.634098, "There": -3.7540603, "C": -0.38441458, "The": -2.1460667, "Since": -2.5616634}], "text_offset": [33]}, "finish_reason": null}], "model": ""}

tapos gamit ko po is
PHP:
$response = getStr($respond, '"text":"','"');
tapos ang response nya lang is <|endoftext|>
paano ko kaya sila kukunin yung laman ng text respond using by 1-2-3, hindi din po sya covertable sa json.
 
Replace mo yung "data:" to ""

Then explode mo sa new line

Tas loop ka sa array then json decode


Parang ganto
Code:
data = "<YUNG DATA>"
parse = data.replaceAll("data: ", "")

arrays = explode(parse)
foreach arrays as array{
    json = json_decode(array)
    // Use json
}
 
Status
Not open for further replies.

About this Thread

  • 6
    Replies
  • 464
    Views
  • 4
    Participants
Last reply from:
LadyClare

Online now

Members online
425
Guests online
1,302
Total visitors
1,727

Forum statistics

Threads
2,277,856
Posts
28,979,305
Members
1,229,115
Latest member
zxckeen
Back
Top